javascript - jQuery/AJAX concurrent access to global variable -
 I'm writing some jQuery code which makes plain Ajax calls. I have a global javascript variable that I need to increase  thread-safe  with every call if it was Java, then I would use  synchronize  but not so: -) 
Here is a code snippet:
  var myval; Function myFunc () {$ .ajax ({url: myurl, type: 'GET', data: {... my data ...}, success: function () {myval ++;}}); }    Given that  myFunc ()  is linked to one click event, how can I ensure that  myvar  is always Safely / Continually increased? I know that I can use  probably   async: false , but I want to avoid it. I'm not even sure that he will do that. 
Thanks for any help!
There is no problem - JS does not cause nuclear problems because there are no user (user-visible) threads [
  There is nothing in JS, in response to it, it is impossible to forget  myval  to forget a piece of code during the event or initial script load salary. , Because the entire  success  callback can be completed before any other event handling code. 
[*] Yes, there are webwalkers, but they use a variable sharing message.
Comments
Post a Comment