jQuery getJSON将结果保存到变量中 [英] jQuery getJSON save result into variable

查看:332
本文介绍了jQuery getJSON将结果保存到变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用getJSON从我的网站请求JSON。它工作得很好,但我需要将输出保存到另一个变量中,如下所示:

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) {

                 });

我需要将结果保存到 myjson 但似乎这种语法不正确。任何想法?

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

推荐答案

调用 getJSON 时无法获得价值,只有在回复之后。

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;
});

这篇关于jQuery getJSON将结果保存到变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆