-1
I am making a system, and in it I need to send several data to the server, basically synchronize an array of objects on a server via json using javascript, until then there is no problem, however the request is $.ajax, which is asynchronous, and so, I have no way to control the data afterwards, nor save the data at the end of the execution of all requests.
I have done with a for, and found on the net, first that could use async:true, however, I also saw that this function has been deprecated, so you should use Promise or callback, however both could not implement, there is some example of how I can do this?
Edited to clarify the problem
Minuting the problem, it consists of a repetition of ajax calls to a server where each object in the array is a registered object in the service, however, at the end of all calls, I save in the localstorage the whole array, this array has a certain consistency, since it is an array of data that may or may not already be in the database, so I use id (provided by the database) to find out if the object is registered, if there is id in the object, then it is in the service.
But back to the main thing, what happens is that when you send a data to the server, the asynchronous call of $.ajax, if you put it so that in each success the data is saved, this results in that in some cases, the end result is information with and without the id. resulting in unforeseen behavior. this pq, the calls ajax, they for being asynchronous, do not end in series, and in parallel being that each one at its time.
You can give an example of ajax(s) (s) that you need to send?
– Sergio
They are basically posts, posts to a server, but the return updates an array that is in a localstorage.
– Andersoney Rodrigues
Your question is VERY confused. You need to divide it into smaller parts. You don’t understand much of what you want. Posting the code would help a lot, including.
– Brunno Vianna