[英]What are the parameters I am supposed to be putting into the send when I am doing an Ajax POST request?
这是来自http://www.javascriptkit.com/dhtmltutors/ajaxgetpost2.shtml的代码,我对此有疑问。
var mypostrequest=new ajaxRequest()
mypostrequest.onreadystatechange=function(){
if (mypostrequest.readyState==4){
if (mypostrequest.status==200 || window.location.href.indexOf("http")==-1){
document.getElementById("result").innerHTML=mypostrequest.responseText
}
else{
alert("An error has occured making the request")
}
}
}
var namevalue=encodeURIComponent(document.getElementById("name").value)
var agevalue=encodeURIComponent(document.getElementById("age").value)
var parameters="name="+namevalue+"&age="+agevalue
mypostrequest.open("POST", "basicform.php", true)
mypostrequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
mypostrequest.send(parameters)
在我的程序中,我想让我发布的内容来自 forms。 那么我应该在发送中设置我的参数是什么? 另外,我不想通过此 Ajax 请求更改文档本身的任何内容,因此在代码的 onreadystatechange 部分中,如果 state 为 4 且状态为 200 而不是更改元素的 innerHTML,我该怎么办?
您应该输入 url 编码数据,例如“name=Frank&last=Jones”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.