How to store different values with the same key in memcache?

jQuery: How can I store the JSON response values in variable?

  • My script as follows: var initilization; function onshow(fileid) { $.ajax({ "url": 'GetTags.ashx?fileid=' + fileid, "dataType": "text", "success": function(result) { initilization = result; alert('success result=' + initilization); } }); alert('initilization=' + initilization); } But the execution results are: success result=Cloud Computing initilization=undefined It looks that the response values can't be stored in variables. How can I store the JSON response values in variable via JS? Thank you.

  • Answer:

    It is stored,  but the alert statement following he $.ajax call is executed before the assignment takes place. It happens because the success callback is called when a result comes from an AJAX call (i.e. asynchronously). I.e. a result of AJAX request should be processed inside a calback. However, you can store them in a global variable and access data later (but make sure, it happens after an assignment had been performed).

Eugene Retunsky at Quora Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.