[英]What are the parameters I am supposed to be putting into the send when I am doing an Ajax POST request?
This is the code from http://www.javascriptkit.com/dhtmltutors/ajaxgetpost2.shtml that I have a question about.这是来自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)
In my program, I want to make the things I post come from forms.在我的程序中,我想让我发布的内容来自 forms。 So what is it that I should be making my parameters in the send?那么我应该在发送中设置我的参数是什么? Also, I don't want to change anything about the document itself with this Ajax request, so in the onreadystatechange part of the code, what should I do if the state is 4 and the status is 200 rather than changing an element's innerHTML?另外,我不想通过此 Ajax 请求更改文档本身的任何内容,因此在代码的 onreadystatechange 部分中,如果 state 为 4 且状态为 200 而不是更改元素的 innerHTML,我该怎么办?
You are supposed to put url encoded data eg "name=Frank&last=Jones"您应该输入 url 编码数据,例如“name=Frank&last=Jones”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.