Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery getson中的getJSON_Jquery_Json_Ajax_Getjson - Fatal编程技术网

Jquery getson中的getJSON

Jquery getson中的getJSON,jquery,json,ajax,getjson,Jquery,Json,Ajax,Getjson,我有两个类似的JSON数据: [{ "productId": "1", "name": "RX7048", "imageUrl": "http://s7d9.scene7.com/is/image", "description": "Modern design.", "price": "229.95", "manufacturerId": "1" }, { "productId": "2", "name": "RB 2132 52 New Wayfarer",

我有两个类似的JSON数据:

[{
  "productId": "1",
  "name": "RX7048",
  "imageUrl": "http://s7d9.scene7.com/is/image",
  "description": "Modern design.",
  "price": "229.95",
  "manufacturerId": "1"
}, {
  "productId": "2",
  "name": "RB 2132 52 New Wayfarer",
  "imageUrl": "http://s7d9.scene7.com/is/image",
  "description": "Best Seller",
  "price": "129.95",
  "manufacturerId": "1"
}, {
  ...
}]
function getAllProducts() {
  $.getJSON('http://meyecare.herokuapp.com/api/v1/products', function(data) {
    var len = data.length;
    for(var i = 0; i < len; i++) {
      //get the name of the Manufacturer by Manufact.-Id         
      var w = $.getJSON('http://meyecare.herokuapp.com/api/v1/manufacturers/' + data[i].manufacturerId);

      $('#products').append("<tr><td class='name'>" + data[i].name +
                            "</td><td><img class='prodImg' src='" + 
                            data[i].imageUrl +  "'/>"+
                            "<td class='manus'>" + w.name + "</td>"+
                            "<td class='descr'>" + data[i].description+
                            "</td>" +
                            "<td>$ " + data[i].price+
                            "</td><td><span class='btn' prodId='" +
                            data[i].productId + "'>Buy me</span></td></tr>");
    }        
  });
}

我尝试在HTML网站中显示它们,如下所示:

[{
  "productId": "1",
  "name": "RX7048",
  "imageUrl": "http://s7d9.scene7.com/is/image",
  "description": "Modern design.",
  "price": "229.95",
  "manufacturerId": "1"
}, {
  "productId": "2",
  "name": "RB 2132 52 New Wayfarer",
  "imageUrl": "http://s7d9.scene7.com/is/image",
  "description": "Best Seller",
  "price": "129.95",
  "manufacturerId": "1"
}, {
  ...
}]
function getAllProducts() {
  $.getJSON('http://meyecare.herokuapp.com/api/v1/products', function(data) {
    var len = data.length;
    for(var i = 0; i < len; i++) {
      //get the name of the Manufacturer by Manufact.-Id         
      var w = $.getJSON('http://meyecare.herokuapp.com/api/v1/manufacturers/' + data[i].manufacturerId);

      $('#products').append("<tr><td class='name'>" + data[i].name +
                            "</td><td><img class='prodImg' src='" + 
                            data[i].imageUrl +  "'/>"+
                            "<td class='manus'>" + w.name + "</td>"+
                            "<td class='descr'>" + data[i].description+
                            "</td>" +
                            "<td>$ " + data[i].price+
                            "</td><td><span class='btn' prodId='" +
                            data[i].productId + "'>Buy me</span></td></tr>");
    }        
  });
}
函数getAllProducts(){ $.getJSON('http://meyecare.herokuapp.com/api/v1/products,函数(数据){ var len=data.length; 对于(变量i=0;i 它在正确的列和行中向我显示具有正确产品的表,但尝试加入制造商名称的列显示“[object object]”,而不是Manufacturername

我找不到错误,有人能帮我吗?

我猜您的“制造商名称”栏是
td
manus
类。如果是这样,那么我假设问题是为什么
w.name
不能正确显示

是异步的。它返回一个承诺,而不是实际的API响应。因此,在这种情况下,
w
是一种承诺,而不是制造商数据


您需要使用
$.getJSON
您第一次使用它的方式(通过传入
success
callback)。

出于某种原因,它现在显示我“未定义”而不是“对象对象对象”,我尝试按照您的建议执行以下操作:函数getAllProducts(){$.getJSON('productsJSON',函数(数据){var len=data.length;for(var i=0;i)结果是is没有显示任何内容,既没有显示任何制造商名称,也没有显示表
$getJSON('manufaJSON/theId')
的响应是什么?我想端点只返回制造商列表,而不是单个制造商。下面是一个示例,演示了我上面的建议。