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:
- var ipAddr;
- jQuery(function() {
-
- // request IP address
- $.getJSON("http://jsonip.appspot.com?callback=?", function(data) {
- ipAddr = data.ip;
- });
- getJSON("http://api.website.com/request?api_token=xxxxxx&IP=" +ipAddr+"&callback=?",
- function(data) {
- /* do something here */
- ................................................................
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!