简体   繁体   中英

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.

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM