【问题标题】:get JSON data from a web-service to make a picture gallery从 Web 服务获取 JSON 数据以制作图片库
【发布时间】:2016-03-18 18:21:28
【问题描述】:

http://www.cs.sun.ac.za/rw334/products.php 提供网络服务? 限制=12&skip=0

我想将其中的数据放入 Javascript 数组中。我四处寻找,我认为我应该这样开始?

  $.ajax({
    type: "GET",
    url: "http://www.cs.sun.ac.za/rw334/products.php?limit=12&skip=0",
    data: {id:id, name:name,url:url},
    contentType: "application/json",
    dataType: "json",
    success: ??
    }
});

我应该如何继续将这些数据从 .php 文件中获取到 Javascript 数组中?

【问题讨论】:

  • 您在这里询问基本的 jQuery 用法...请阅读 jQuery 文档,他们将提供您需要的有关 ajax 请求和成功回调的所有信息。

标签: javascript php arrays json ajax


【解决方案1】:
 product = [];
  $.ajax({
    type: "GET",
    url: "http://www.cs.sun.ac.za/rw334/products.php?limit=12&skip=0",
    dataType: "json",
    success: function(data) {
        $(data.products).each(function(i, products){
            product[products.id] = products.name;
        });
        console.log(product);
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多