在这里,我已经贴我的code,我想返回$阿贾克斯的响应作为功能反应的()。但在此之前的结果出现Ajax调用,它返回空F。请在这方面的帮助。
A =功能()
{
变种F ='';
$阿贾克斯({
网址: 'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=immaulikvora&count=1&page=1&include_entities=1&callback=?',
数据类型:JSON,
异步:假的,
成功:功能(数据){
F =数据;
}
});
返回F;
};
变种盖子=一();
警报(盖);
解决方案
我猜你正在使用jQuery 1.8 +
http://api.jquery.com/jQuery.ajax/
请阅读印刷精美。
在jQuery 1.8,采用异步的:假以jqXHR($ .Deferred)是 德precated ;
您必须使用完整/成功/错误回调。
尝试
http://jsfiddle.net/UgrLE/
Here I have pasted my code, I want to return the response of $.ajax as response of function a(). But before the result comes up of ajax call, it is returning the empty f. please help on this
a = function()
{
var f = '';
$.ajax({
url: 'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=immaulikvora&count=1&page=1&include_entities=1&callback=?',
dataType: 'json',
async: false,
success: function(data) {
f = data;
}
});
return f;
};
var lid = a();
alert(lid);
解决方案
I guess you are using jQuery 1.8+
http://api.jquery.com/jQuery.ajax/
Please read the fine print.
As of jQuery 1.8, the use of async: false with jqXHR ($.Deferred) is deprecated;
you must use the complete/success/error callbacks.
try
http://jsfiddle.net/UgrLE/