Monday 1 January 2018

javascript - jQuery getJSON save result into variable





I use getJSON to request a JSON from my website. It works great, but
I need to save the output into another variable, like
this:



var myjson=
$.getJSON("http://127.0.0.1:8080/horizon-update", function(json) {


});


I need to save the
result into myjson but it seems this syntax is not correct. Any
ideas?



Answer




You can't get value when calling
getJSON, only after
response.



var
myjson;
$.getJSON("http://127.0.0.1:8080/horizon-update",
function(json){
myjson =
json;
});


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...