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' –