ajax回调函数中如何传递对象 看你ajax怎么写的了试试 $.ajax.setErrorList = function(){alert('this.errorList')} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 this是指当前我自定义的一个对象,不是指$比如function aaa(){this.a=0;this.str="sdf";}aaa.prototype={getdata:function(){$.ajax({type: "GET",async:false,url: g.ConfigError, dataType: "xml", complete: this.setErrorList}); },setErrorList:function(data){this.str=data;}}主要作用是在获取到数据之后,将相关数据赋于本对象的属性。 格式规范一点,上面的看起来太累了。function aaa(){ this.a=0; this.str="sdf";}aaa.prototype={ getdata:function(){ $.ajax({ type: "GET", async:false, url: g.ConfigError, dataType: "xml", complete: this.setErrorList }); }, setErrorList:function(data){ this.str=data; }} 那也要看你的$.ajax是怎么定义的啊可以这样试试getdata:function(){ this.call($.ajax); $.ajax({ type: "GET", async:false, url: g.ConfigError, dataType: "xml", complete: this.setErrorList }); }, 我晕,明白你的意思了。$.ajax一个ajax的封装,是jquery库中定义好的。相当于新建了一个xmlhttp请求,从服务器上读取一个文件的数据,并且在完成读取后,触发complete指定的回调函数,即:this.setErrorList。而这个函数的定义必须是function fn(data){} 刚刚下了个JQ看下这样试试 getdata:function(){ this.call($.ajax); $.ajax(jQuery.extend({ type: "GET", async:false, url: g.ConfigError, dataType: "xml", complete: this.setErrorList },this)); }, 我想就按你这个写法,估计还是不行。jquery只是一个工具而已,其内部没有实现传递对象。抛开jquery,我现在是想知道一个思路,或者说是一个设计模式,如何在回调中传递对象。好像在settimeout时,函数传递对象的性质一样。 问题已经自行解决了,非常感谢你的提示。最终我是使用Function.call解决的。 c#后台往前台输出table(多组radio)如何取值? juqery仿照 flash效果求助。 关于正则表达式的疑问 小妹请教各位前辈日期验证的问题! 框架网页跨域提示无权限,如何解决? 判断非法字符串问题?难题!希望高手来!谢谢 请教一个图片另存为格式的问题 谢谢~~~ JavaScript中如何替换QueryString? 用户在输入时自动将他转为小写 在线等! 转换含有特殊标识的字符成下拉框 form表单中action?? 用for循环生成多个checkbox但是name都一样,这样如何去实现选择一个复选框就显示一个testarea取消一个复选框就不显示刚才的testarea
比如
function aaa()
{
this.a=0;
this.str="sdf";
}
aaa.prototype={
getdata:function(){
$.ajax({
type: "GET",
async:false,
url: g.ConfigError,
dataType: "xml",
complete: this.setErrorList
}); },
setErrorList:function(data){
this.str=data;
}
}主要作用是在获取到数据之后,将相关数据赋于本对象的属性。
{
this.a=0;
this.str="sdf";
}
aaa.prototype={
getdata:function(){
$.ajax({
type: "GET",
async:false,
url: g.ConfigError,
dataType: "xml",
complete: this.setErrorList
});
},
setErrorList:function(data){
this.str=data;
}
}
可以这样试试
getdata:function(){
this.call($.ajax);
$.ajax({
type: "GET",
async:false,
url: g.ConfigError,
dataType: "xml",
complete: this.setErrorList
});
},
而这个函数的定义必须是function fn(data){}
这样试试
getdata:function(){
this.call($.ajax);
$.ajax(jQuery.extend({
type: "GET",
async:false,
url: g.ConfigError,
dataType: "xml",
complete: this.setErrorList
},this));
},
jquery只是一个工具而已,其内部没有实现传递对象。抛开jquery,我现在是想知道一个思路,或者说是一个设计模式,如何在回调中传递对象。好像在settimeout时,函数传递对象的性质一样。