I am calling a post several times to create objects on a server, the post is wrapped in a promise. I make many promises and pass it to Q.all, but when it is resolved, all objects in the array have a single ID and only one object is created on the server.
Here my code is
for (var i = txArray.length - 1; i> = 0; i--) {txArray [i]. _ Action = 'update'; Promises.push (newVertex (url)); }; Return Q.all (promises) Then (work (result) {console.log (results);}); Function Newertex (URL) {var deferred = Q.defer (); Var xhr; Try {Xhr = new_xhr (); } Hold (e) {deferred.reject (-1); Refund refund. } Xhr.open ('post', url, true); Xhr.onreadystatechange = function () {if (xhr.readyState === 4) {if (xhr.status === 200) {deferred.resolve (xhr.responseText); } And {deferred .reject (xhr); }}}; Xhr.send (); Refund refund. } Why does not the result give returns to all items with the same ID? Does anyone have any suggestions.
I have succeeded in solving this issue. The post had the header with content type: application / jsn That's why the server is expected to pass some data to it. Passing some Jason data or even '{}' resolved the problem.
For example:
xhr.send ('{}'); Thanks to each body response, it all helps.
No comments:
Post a Comment