3
我无法返回此函数的结果。从Javascript函数返回变量
function get_duration() {
var a = '';
$.ajax({
url: "http://gdata.youtube.com/feeds/api/videos?q=3KMz3JqRByY&max-results=50& format=5,1,6",
dataType: "jsonp",
success: function (data) {
re2 = /seconds='(\d+)'/ig;
while (re.exec(data) != null) {
a = re2.exec(data);
}
}
});
return a;
}
在'success'回调中使用'return' –
它与你的AJAX调用是异步的有关,你的问题也被问及(并回答)了一百万次,例如[here](http:///stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call?lq=1)。 –
在你的ajax中使用'async = false' –