var slider = {
'info': 'something',
'get': function(){
var that = this;
$.get("data/index.php?c=Slider&a=get","",function (response) {
that.info = response;
console.log(that.info);
})
console.log(that);
return this.info;
},
'create': function(){
console.log(this.info);
}
}
slider.get();
slider.create();
怎么才能把response数据拿出来呢? 也就是说怎么才能让slider.info更新为ajax回调的数据?
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
因为
ajax是异步的,因此你执行slider.get()拿到的肯定是修改前的info,建议使用Promise,或者用回调的方式从get里获取数据response就是你data/index.php返回的数据啊。没什么疑问啊。
你的response是什么类型的。是json吗还是html或者text的。
如果是text或者text直接获取就行了。如果是json的话,因为你没有指定dataType为json所以,ajax会根据你返回的header信息判断是否是json,如果是json会自动转成json格式的。然后直接用response.xxxx就可以用了。
如果没有在header了里设置json,直接把response转成json格式即可:var j=eval("("+response+")")