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?

推荐答案

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相关问答推荐

提交表单时运行自定义验证脚本

使用jQuery筛选器搜索输入仅适用于单词的一部分

使用jquery ui来回滑动切换

我需要在上一个表格单元格中显示计算结果

从文本区域获取值

如何从 onclick div 属性检测 Javascript 中的 control+click?

使用 jQuery 时何时/为什么要在变量前加上$?

$(document).ready(function() VS $(function(){

$.post 和 $.ajax 之间的区别?

如何使用 jQuery Select 所有复选框?

jQuery中的正则表达式字段验证

JQuery手风琴自动高度问题

如何判断元素是否在屏幕外

为不同的 node 类型配置jstree右键上下文菜单

如何检测是否安装了 Flash,如果没有,显示一个隐藏的 div 通知用户?

将图像 url 转换为 Base64

$(document).ready(function(){});页面底部的 vs 脚本

带有回调ajax json的jQuery自动完成

fancybox2 / fancybox 导致页面跳转到顶部

使用 jQuery 检测元素内容的变化