【发布时间】:2014-04-19 04:37:59
【问题描述】:
不知道如何提出问题,所以如果您愿意,请随时更改。
那么我的代码有什么问题?
(function() {
//--> DOM is ready
var _$ = {
g: function(u,c){ // c is callback function
x=new XMLHttpRequest();
x.onreadystatechange = function(c){ // same c isn't it?!
d="", e=null;
if (x.readyState==4) {
if (x.status==200) { d = x.responseText; }
else { e = x.statusText; }
c(e,d); // how come c is an object
// and not a function here?!
}
}
x.open("GET",u,true); x.send(null);
}
}
//--> Call our method:
_$.g("http://copy.com/K8UjOnVoyUCiNmPC/qcm/0/1/2.json",
function(e,d){
if(!e){
window.alert(d);
}
}
);
//--> .DOM
})();
任何线索我在这里错过了什么?怎么弄好?
谢谢!
【问题讨论】:
-
在形参列表中包含 c 与在第一行用 var 声明 c 相同函数:它创建一个新的局部变量c,它不引用“外部”c。
标签: javascript ajax oop