1

I have a function which makes an ajax post when the server returns a a successful response I wan't to set a flag variable and return it, whatever happens it won't change the flag variable outside the ajax call, if I log it in the success callback it is correct but when I log it again at the very end of the function before I return it it is always the default value.

function addTo(objId, name){
   flag = null;
   $.ajax({
        type: "POST",
        url: "/prcesses/add",
        dataType: 'json',
        data:  {
            name: name,
            id: objId
       },
       cache: false, 
       success: function(response) {     
            flag = response.success;
      }
   });
  return flag;
}

Can anyone tell me how my scope is wrong?

Anthony Forloney
  • 90,123
  • 14
  • 117
  • 115
Barry Hamilton
  • 943
  • 3
  • 15
  • 35
  • 3
    http://stackoverflow.com/questions/11917734/jquery-ajax-call-success-how-do-i-change-a-global-variable-in-the-wrapper-javas – danronmoon Jan 15 '15 at 18:01

0 Answers0