开发者

How do I use Two ajax calls at the same time to process records and update the HTML?

开发者 https://www.devze.com 2023-03-01 00:52 出处:网络
I am developing an application to process the daily credit card sales of a store. All the data necessary to process the transactions through the merchant is stored in a mySQL database. When the user c

I am developing an application to process the daily credit card sales of a store. All the data necessary to process the transactions through the merchant is stored in a mySQL database. When the user clicks on "Process Transactions" a page loads displaying each transaction row by row in a HTML table. Using onLoad() I am using ajax to call a .php page which in turn queries the database for all the transactions, and then in a loop processes the transactions through the merchant and updates the database with either a success or fail. This part is working perfectly.

My question is this: I would like to update the HTML table as the processing is taking place and turn the HTML table rows red for fail and green for success. Trying to do this in a For Loop (updating each row af开发者_JAVA技巧ter each transaction processes) does not work. I know I can use AJAX setInterval() to call another .php page every 2 seconds which queries the database for completed records and updates the HTML table with the results returned. My .php pages are written and working. I have the AJAX set up and working for the first part (processing the transactions). What I need to know is where to put the 2nd AJAX call that updates the HTML table? Pseudo code will be fine or a link to an example would also be helpful.

Thanks for your help!


It's not practical to do what you are suggesting by continuously hitting the server to check for 'completion'.

I am using ajax to call a .php page which in turn queries the database for all the transactions, and then in a loop processes the transactions through the merchant and updates the database with either a success or fail.

This loop should also update the tables with a success or fail, if you post the code where you are having a problem, I'd be glad to extend this answer and help solve it.

0

精彩评论

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

关注公众号