I am inserting data via AJAX, and sending the data using a GET request. Now I want to send the data using a POST request instead. How should I go about converting this code?
<form name=myf id=myf>
<input type=text name=user>
<input type=text name=email>
<input type=button onclick="ready();" value="Add">
</form>
<script languague=javascript>
function ready(){
var url="adduser.php";
var parm="?user="+document.myf.user.value;
parm+="&email="+document.myf.email.value;
//alert(parm);
var target=document.getElementById('abc');
add(url,parm,target);
document.getElementById('myf').reset();
}
</script>
Use jQuery:
$.post(url, {'user':user, 'someotherdata':'data'}, function (response) {
//do the result oriented activities
});
var xmlhttp;
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
//Code after ajax response
}
}
xmlhttp.open("POST","adduser.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("user="+document.myf.user.value+"&email="+document.myf.email.value");