Accessing AJAX variable data outside of AJAX query

Discussion in 'JavaScript' started by fri3ndly, Feb 17, 2011.

  1. #1
    Hello

    I have the following AJAX call:

    
    $.ajax({
    		  type: "POST",
    		  url: "/ajax.php?q=portfolio",
    		  data: {client_id: $('#portfolio-image').attr('class')},
    		  async: false,
    		  success: function($data){
    			$data = eval('(' + $data + ')');
    			  $id = $data[0]['id'];
    			  $title = $data[0]['title'];
    			  $image = $data[0]['image'];
    			  
    			  $('#portfolio-image').html('<img src="/assets/images/portfolio/thumbs/' + $image + '" alt="' + $title + '"  title="' + $title + '" id="img-' + $id + '" />');
    			  }
    
    	  });
    
    Code (markup):
    I would like to access the $data variable from another page function without calling AJAX. I read that that the only way to do this is to have async: false but it hasn't helped.

    The reason I need to do this is that the ajax query returns an array of images, then the next and previous buttons need to simply change the position of the array.

    Thanks for your help
     
    fri3ndly, Feb 17, 2011 IP
  2. fri3ndly

    fri3ndly Active Member

    Messages:
    111
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Just to let you know I have sorted this:

    just needed to give the variable a window.variable_name to make it global
     
    fri3ndly, Feb 17, 2011 IP