如何使用POST方法发送以下请求?
lun = document.getElementById("lun").value;
lp = document.getElementById("lp").value;
url = "lun="+lun+"&lp="+lp;
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("login").innerHTML=xmlhttp.responseText;
}
else{
document.getElementById("login").innerHTML="Loading";
}
}
xmlhttp.open("GET",'login.php?'+url,true);
xmlhttp.send();
答案 0 :(得分:3)
要使用的HTTP方法,例如“GET”,“POST”,“PUT”,“DELETE”等。忽略非HTTP(S)URL。
xmlhttp.open("POST",'login.php',true);
xmlhttp.send(url);
参考:https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
答案 1 :(得分:1)
发布
试试这个
xmlhttp.open("POST","login.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send(url);
以下是演示http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_post2
答案 2 :(得分:0)
xmlhttp.open("POST","login.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("lun=myuser1&lp=mellon");