Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple AJAX posts to Web Service that returns value. Should I synchronize?
    text
    copied!<p>My website is sending ajax posts to my web service, and the web service in return will return a json and that json will be further use in success callback.</p> <p>Now, here's my problem, when my website is sending multiple ajax posts, it seems that those json that the web service returned gets jumbled up.</p> <p>I'm thinking on synchronizing either the ajax posts or the web service (REST)? I've read that you don't need to synchronize REST services, is that true? If synchronizing is the solution, where should I synchronize it? Will async: false in ajax synchronize the posts?</p> <p>Thanks.</p> <p>I thought about including some codes:</p> <p>Web Service:</p> <pre><code>@POST @Override @Produces("application/json") @Consumes("application/json") public Customer create(Customer cust){ custManager.save(cust); return custManager.getCust(custManager.getCount()); } </code></pre> <p>AJAX:</p> <pre><code>$.ajax({ url: custURL, type: 'POST', data: JSON.stringify(sdata), dataType: 'json', contentType: 'application/json; charset=utf-8', success: function(json){ var cust = JSON.parse(JSON.stringify(json)); var newId = cust.id; updateCustId(oldId, newId); } }); </code></pre> <p>What it does is it post to web service the data of the customer, and the web service designates an id for it and it return it to the client to update its customer id. That's not it all, I'm also updating other tables that is reference to the old customer id to the new generated from server, and after updating these other tables, it also will be send to the web service. The tables I'm talking about is web sql, its queries too works asynchronously. So end result is sometimes the ids got jumbled up and the other tables were send to the web service but the customerid it used is still the old one (I've used callbacks, ensured that it needed to be updated first before it will be sent to the server). </p> <p>making my ajax calls async: false to make them synchronous and not get jumbled together works.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload