assign data from $.getJSON() to global variable

assign data from $.getJSON() to global variable

Hello,

I am developing a jQuery application and I need to get a parameter from one getJSON request, then use it in another.


Here's a code example that of course is not working:

  1. var ipAddr;
  2. jQuery(function() {
  3.    
  4.     // request IP address
  5.     $.getJSON("http://jsonip.appspot.com?callback=?", function(data) {
  6.         ipAddr = data.ip;
  7.     });
  8.      getJSON("http://api.website.com/request?api_token=xxxxxx&IP="  +ipAddr+"&callback=?",
  9.     function(data) {
  10. /* do something here */
  11. ................................................................
I know that getting IP address is very easy using PHP or other server side scripting language but I am bound on using HTML and jQuery only.

I would appreciate any advice or help you might have to offer for this one.

Thank you!