开发者

Functions too fast? So they get skipped?

开发者 https://www.devze.com 2022-12-13 10:23 出处:网络
Wit开发者_Go百科h a function a div-popover gets called and filled with dynamic data using Ajax, PHP, MySQL and some HTML/CSS. All goes fine.

Wit开发者_Go百科h a function a div-popover gets called and filled with dynamic data using Ajax, PHP, MySQL and some HTML/CSS. All goes fine.

When I want to delete an entry in the list just popped over it functions as it should. When I send an update request for my list it also goes the way I want it. But, when i call delete(); update(); right after eachother my first function gets skipped somehow.

When I place alert()'s in both functions I see both functions are getting executed and the scripts walk fine through my ajax function, PHP ajax handler and returns the result back to the user, and with the alerts on all is going well too!

So my question is, are my functions too fast? Or is there something I'm missing here which is causing the non-delete?

Solution I've moved the update call to the line after the xmlHttp.resonseText in the delete function. In that way the second function call gets executed after the first function is done. Thanks all!


My guess would be that you haven't thought about the A in AJAX. It stands for asynchronous. That means that when you perform an XmlHttpRequest call, it will be executed in the background. I.e. after you've called delete(); the script will immediately continue and execute update();.


javascript will just execute the next statement while an ajax call is going on. Most ways of using ajax have an on complete function that you can call, so that code that you want executed after an ajax call is called only afterwards.

I've not worked with php, but it may be worth looking into that.


It sounds like the two methods are executed at the same time (asynchronously) since its AJAX.

you want them to be excuted synchronously.

See this patterns page for more information... Ajax patterns

0

精彩评论

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