【发布时间】:2011-02-10 23:36:11
【问题描述】:
我是 JS 新手,很难阅读以下 JS 代码。
函数的第一个参数是一个PHP脚本的url,第二个是一个字符串。
让我感到困惑的是如何阅读行后的代码: self.xmlHttpReq.open('POST', strURL, true);
这之后会发生什么?我应该在这一行之后查看哪些代码?剧本? 打开后会发生什么?
function check_detail(strURL, pids)
{
var xmlHttpReq = false;
var self = this;
// Mozilla/Safari
if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
}
// IE
else if (window.ActiveXObject) {
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
self.xmlHttpReq.open('POST', strURL, true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.onreadystatechange = function()
{
if (self.xmlHttpReq.readyState == 4)
updatepage(self.xmlHttpReq.responseText, pids);
}
self.xmlHttpReq.send(getquery(pids));
}
【问题讨论】: