-1

I want to array my $.getJSON values outside of the $.getJSON. Here is the code:

 $.getJSON("www.someurl.com/", function(results){
    value = results;
 });

 document.write(value);

I want to write my value outside of the $.getJSON. How can I array my value?

user2692270
  • 35
  • 1
  • 6
  • Possible duplicate of [How to return the response from an asynchronous call?](http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-asynchronous-call) – Paul Roub Oct 17 '15 at 01:56

1 Answers1

0

The problem is in your way to write this JSON result. To be clear, $.getJSON is an asynchronous request, so your line 2 (value=results) will be executed after your line 4 ( document.write(value) ).

To solve, try something like this:

$.getJSON("www.someurl.com/", function(results){
   value = results;
   document.write(value);
});

Got it?

Túlio Castro
  • 1,313
  • 10
  • 17