开发者

What are the parameters I am supposed to be putting into the send when I am doing an Ajax POST request?

开发者 https://www.devze.com 2023-03-17 12:16 出处:网络
This is the code from http://www.javascriptkit.com/dhtmltutors/ajaxgetpost2.s开发者_C百科html that I have a question about.

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"

0

精彩评论

暂无评论...
验证码 换一张
取 消