将参数传递给匿名onreadystatechange回调的正常纯javascript(即非JQuery)方式是什么?将参数传递给ajax onreadystatechange回调?
例如:
function doRequest(){
/* Get an XMLHttpRequest in a platform independent way */
var xhttp = getXmlHttpRequestObject();
var msg="show this message when done"; /* another variable to pass into callback */
/* How do I pass 'msg' and 'xhttp' into this anonymous function as locals
named 'x' and 'm'??? */
xhttp.onreadychangestate=function(x,m)
{
if(x.readyState == 4)
{
alert(m);
}
}
/* do the open() and send() calls here.... */
}
谢谢。这个答案促使我学习了更多关于Javascript的知识。我真正需要知道的是关闭是如何工作的。 – 2011-12-21 15:17:44
http.onreadystatechange = function(){ var xmlHttp = this; if(xmlHttp.status == 200)console.log(“We got it!”); } }; – Abbas 2018-01-25 09:09:23