我通过AJAX插入数据,并使用GET请求发送数据。现在我想使用POST请求发送数据。我应该如何转换此代码?
<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>
答案 0 :(得分:1)
使用jQuery:
$.post(url, {'user':user, 'someotherdata':'data'}, function (response) {
//do the result oriented activities
});
答案 1 :(得分:0)
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");