This is the code from http://www.javascriptkit.com/dhtmltutors/ajaxgetpost2.s开发者_C百科html that I have a question about.
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. 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?
You are supposed to put url encoded data eg "name=Frank&last=Jones"
精彩评论