开发者

jQuery AJAX initial data problem for dynamic dropdowns

I have a problem with initialization of dynamically filled dropdowns in jQuery. Basically, I have function fillCityList and it makes AJAX call to fill the cities by the passing country. Because this is used in Edit form, I have a default City value in id_cityHidden field. Actually the code below works well.However, because fillCityList takes long time to fill the city list, while default city is selected, the city list may not be ready.

$(document).ready( function() {
    fillCityList(1);
    $('#city').val($("#id_cityHidden").val());  
});

I know there is a solution like "call function at complete stage of AJAX call" but I just need it during initialization. One solution might be setting a timeout or delay between fillCityList and $('#city').val($("#id_cityHidden").val()) however, it is n开发者_如何学Cot a good solution of course.

What is the best way to do this ?

Thanks


I would suggest you build your ajax to use the 'complete' function, then update the value.

http://api.jquery.com/ajaxComplete/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜