开发者

jQuery ajaxComplete on specific Ajax call

开发者 https://www.devze.com 2022-12-14 13:56 出处:网络
I have this function that puts some data with Ajax call in a php variable. When the data is put I show开发者_如何学Go some message that the data is put and then I show a small part of that data.

I have this function that puts some data with Ajax call in a php variable. When the data is put I show开发者_如何学Go some message that the data is put and then I show a small part of that data.

The problem is that the javascript shows the message that it is put when the Ajax call is still putting it, so the part of the data I want to show isn't there yet.

I have a work around whit a delay of some microseconds that pauses the rest of the javascript to be executed. But this doesn't work very well.

So I came across the ajaxComplete event but this executes every the time any Ajax call is complete and I just want it to execute when that specific call (where I put the data) is complete. Is there a way to do this? Or is there an other way to execute the rest of the JavaScript only when the Ajax call is complete?


You could try calling the php function that puts the data synchronously so that it won't return until it is finished putting all the data. Using the jQuery ajax function, include

async: false

in the options parameter to do this.

Presumably your existing code is along the lines of

//put data
//read data -this might be executed before all the data is put

but with a synchronous call the read data line will only be executed when putting the data is complete.

0

精彩评论

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