jQuery cannot preserve data after .ajax() call -


I am trying to make a simple call where I get the data from $ .ajax () and save it Is a global variable that I can use in a function called ajax call.

Why the variable is not being set? Why is the value determined by me lost?

  jQuery.support.cors = true; $ .myNamespace = {Timer ID: "In Namespace"}; $ (Document) .ready (function () {$ ("# btnSkip") Click (function () {alert ($ myNamespace.timerID); startCall ();}); turn the function call () {$ .myNamespace} TimerID = "startCall ()"; Warning ($ .myNamespace.timerID); Finished call (); Alert ($. MyNamespace.timerID);} Function Fincol () {$ .myNamespace.timerID = "Finnish call ( ); "Warning ($ mynamespace.timerID); $ .ajax ({type:" GET ", url: getUrl, processData: false, contentType:" application / json; charset = utf-8 ", data type:" Json ", success: function (data) {$ .myNamespace.timerID =" Ajax in successful call "; warning ($ .myNamespace.timerID);}, error: function (xhr, position, error) {GetSongInfoFailed (xhr, position, error);}}}}} GetSongInfoFailed (xhr, status, error) {warning ('service call failed:' + xhr + '+ position +' '+ error);}});   

Output to code in alert () s:

  1. in namespace
  2. End call ()
  3. Successful call in AJAX Code>
  4. the last call ()

    Why to succeed in the last variable "in the end call" (instead of ")" Is the set "Pu ka ra na"?

    Note, I'm not a jQuery or Javascript expert

    Thanks a lot!

    Your success callback function function GetSongInfo successful (C) { If (result! = Null) {$ .myNamespace.timerID = "Ajax calls in successful"; Warning ($ myNamespace.timerID.); } Else {}}

    You have an invalid request variable where your function becomes as C of input data As

Comments