jQuery:可以在继续之前等待$ .get完成加载吗? [英] jQuery: Possible to wait for $.get to finish loading before continuing?
本文介绍了jQuery:可以在继续之前等待$ .get完成加载吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在继续循环之前,下面的脚本不会等待$ .get完成加载页面:
The folowing script does not wait for $.get to finish loading the page before continuing with the loop:
$.each(data.songs, function(index, val) {
$('#nowartist')
.append('song starting');
$.get("http://localhost/play.php", function(data){
alert('done');
});
});
数据是JSON对象
任何我们将非常感谢您的想法或意见。
Any ideas or comments will be greatly appreciated.
推荐答案
$.ajax({
async: false,
type: 'GET',
url: 'http://localhost/play.php',
success: function(data) {
//callback
}
});
应该这样做。
< a href =http://docs.jquery.com/Ajax/jQuery.ajax#options =noreferrer> http://docs.jquery.com/Ajax/jQuery.ajax#options
这篇关于jQuery:可以在继续之前等待$ .get完成加载吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文