开发者

delay execution of statement until preveouus binding is still in progress (jquery, ajax)

in my page i am calling a controller using $.get with some parameters ,

that controller returns me a view page (.aspx), now, i bind that page to a different div every time as this function can be iterated (or called multiple times) these div s are already created and then result is mapped to each div

function getview(Name, Parameters, Target) {
     $.get('Home/Submit',
                    { Name: name,
                      Parameters: Parameters
                    },

       function(result) {

           $("#" + Target).html(result);
           //alert("something");

       });
}

this method is called as:

<div id="{{'_Temp' + Id}}">{{getAction('_AddToFavorite', 'ContentId,'
                                    + Id + ',Version,' + Version + ','li_ContentFavorites_Temp'
                                    + Id)}} </div>

Now what happens here is the html gets bind to respective div but only when that 'alert()' is there otherwise the view page gets bind randomly (ie sometime it does sometimes it doesn't) but for last iteration it does.

**I think ** that this is because before the data is actually bind to the respective div the next data(viewpage) comes in.

is there any way to make 开发者_StackOverflow中文版process stop (or delay) so to bind data properly.


if you use .ajax you can use more options - one of these is timeout


I had this problem figured out in more then one way, but the easiest solution is always based on jquery ajaxqueue plugin. It just does ajax "one by one" :)

You could stay with Your way, but it would require a lot of debugging - I think Your problem is related to some variables being less local than You think. If You want to load without queueing - please post more details or a link to an example page

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜