【问题标题】:how to get the json data from the url in jquery?如何从jquery中的url获取json数据?
【发布时间】:2012-08-28 10:52:06
【问题描述】:

如何从 URL 中获取 json 数组。我将 mydata 声明为变量。如何将 json 数组获取到 mydata 中?使用以下 ajax

var mydata;
$.ajax({
 url: someurl,
 dataType: 'json',
 success: function() {

  }
});

【问题讨论】:

  • 普通,你自己差点搞定了! :p
  • @PeterSzymkowski:当我第一次阅读它时,甚至我第一次认为他的意思是从查询字符串中提取参数。但是,是吗?

标签: ajax json jquery getjson


【解决方案1】:
var mydata;
$.ajax({
   url: someurl,
   dataType: 'json',
   success: function(data) {
      mydata = data; 
      console.log(mydata);
   }
});

或者你可以使用$.getJSON()函数

【讨论】:

    【解决方案2】:
    Try this:-
    
        ***$.ajax({
         url: someurl,
         dataType: 'json',
         success: function(mydata) {
    foreach(var data in mydata){
    //do something.....    
    }
          },
    failure: function()
    {
    //error message
    }
        });***
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-13
      • 1970-01-01
      • 2022-12-22
      • 1970-01-01
      • 1970-01-01
      • 2012-04-17
      • 1970-01-01
      相关资源
      最近更新 更多