你好我有这样的序列
$(document).ready(function() {
$("#ctl00_txtsearch").autocomplete({
source: function(request, response) {
$.ajax({
// Here is the code of autocomplete which is requesting
// data and binding as autocomplete
});
});
});
var aa=bindonload();
});
这是我要在页面加载时调用的另一个函数
function bindonload() {
$.get( "minicart.aspx#mydatacontent", function( data ) {
var resourceContent = data;
var mini=$(resourceContent).find('div#pnlminicart');
$('#smallcart').html(mini);
});
return false;
}
所以,我的实际问题是页面加载时 首先
如果文本框有一些值,那么bindonload()
调用然后自动完成? 但是当页面加载并突然我开始写入自动完成文本框然后直到 bindlonload函数被执行自动完成将无法正常工作。
我不知道如何处理它我已经使用 async:true 但它无法正常工作我不想等待第二个进程
提前致谢....
答案 0 :(得分:2)
嗯..我猜...应该是..你 loaddata()不应该花费太多时间来加载。
如果有任何优化方法,请查看。
如果你的ajax请求对另一个请求有依赖性,那么就不能使它并行
如果您真的想要并行ajax请求,则必须使用以下内容:
$.when($.ajax("URL1"), $.ajax("URL2"))
.then(myFunc, myFailure);
希望有所帮助......
注意:Ajax调用不应该依赖
<强>更新强>
$.when( $.ajax( "/page1.php" ), $.ajax( "/page2.php" ) ).done(function( a1, a2 )
{
// a1 and a2 are arguments resolved for the page1 and page2 ajax requests, respectively.
// Each argument is an array with the following structure:
[ data, statusText, jqXHR ]
var data = a1[ 0 ] + a2[ 0 ]; // a1[ 0 ] = "Whip", a2[ 0 ] = " It" if ( /Whip It/.test( data ) ) { alert( "We got what we came for!" );
}});
在上面的示例中,您可以看到两个ajax请求并行执行
在完成两个请求之后,即在成功完成两个函数时,正在执行添加操作
同样,您可以将$.ajax("/page1.php")
替换为loaddata()
,然后
$.ajax("page2.php")
与您的Auto Complete request
。
他们都将执行Parallely