Topic: store an ajax response into a global variable

Hi,

I'm trying to store an ajax response into a global variable.
And afterwards show it through an alert.
I've been at it for hours and hours but I cant get it to work. Please help.

Here's my code:

   var numberofpics;
  
     $.ajax({
    data: {'<%= session_key_name %>' : encodeURIComponent('<%= u cookies[session_key_name] %>'),
          'authenticity_token'  : encodeURIComponent('<%= u form_authenticity_token if protect_against_forgery? %>')},
    dataType:'script', 
    type:'get', 
    url: '<%= countpics %>'  ,
        success: function(response) {    
          numberofpics = response;
                }
    });



alert(numberofpics);     // this gives undefined for numberofpics or [Object object] for $(numberofpics)

Re: store an ajax response into a global variable

Nevermind. The response won't be received yet at the time I call alert.