Post all values with variables in data section of jQuery ajax
HTML PART
<script type="text/javascript" src="../js/jquery-1.6.js"></script>
<input type="button" name="postButton" id="postButton" value="Do Add" onclick="doAddAction();"/>
<script language="javascript">
function doAddAction() {
var a1,a2,a3;
var a1Val,a2Val,a3Val;
var urlStr="xmlPost.php";
var postOrGet="POST";
var ans;
a1Val="This is a1 val";
a2Val="This is a2 val";
a3Val="This is a3 val";
var variableAndValue={a1:a1Val,a2:a2Val,a3:a3Val};
ans=doAdd(urlStr,postOrGet,variableAndValue);
alert(ans);
}
function doAdd(urlStr,POSTorGET,variableAndValue) {
var ans="";
$.ajax( {
type: POSTorGET,
async: false,
url: urlStr,
data: variableAndValue,
timeout: 9999,
cache:false,
success: function(msg){ans=msg;},
error: function(xhr) {
if (xhr.responseText)
ans=xhr.responseText;
else
ans="I don't know! My Processor Has Been HACKED!";
}
}
);
return ans;
}
Php or any other language part:
<?php
$a1=$_POST['a1'];
$a2=$_POST['a2'];
$a3=$_POST['a3'];
$val=$a1."=".$a2."=".$a3;
if($a1!="" && $a2!="" && $a3!="")
echo "<br/>Hi ".$val;
else
echo "Hi There are no any value";
?>
HTML PART
<script type="text/javascript" src="../js/jquery-1.6.js"></script>
<input type="button" name="postButton" id="postButton" value="Do Add" onclick="doAddAction();"/>
<script language="javascript">
function doAddAction() {
var a1,a2,a3;
var a1Val,a2Val,a3Val;
var urlStr="xmlPost.php";
var postOrGet="POST";
var ans;
a1Val="This is a1 val";
a2Val="This is a2 val";
a3Val="This is a3 val";
var variableAndValue={a1:a1Val,a2:a2Val,a3:a3Val};
ans=doAdd(urlStr,postOrGet,variableAndValue);
alert(ans);
}
function doAdd(urlStr,POSTorGET,variableAndValue) {
var ans="";
$.ajax( {
type: POSTorGET,
async: false,
url: urlStr,
data: variableAndValue,
timeout: 9999,
cache:false,
success: function(msg){ans=msg;},
error: function(xhr) {
if (xhr.responseText)
ans=xhr.responseText;
else
ans="I don't know! My Processor Has Been HACKED!";
}
}
);
return ans;
}
Php or any other language part:
<?php
$a1=$_POST['a1'];
$a2=$_POST['a2'];
$a3=$_POST['a3'];
$val=$a1."=".$a2."=".$a3;
if($a1!="" && $a2!="" && $a3!="")
echo "<br/>Hi ".$val;
else
echo "Hi There are no any value";
?>