简体   繁体   中英

get JSON data from a web-service to make a picture gallery

A web-service is available at http://www.cs.sun.ac.za/rw334/products.php ? limit=12&skip=0

I want to get the data in there into a Javascript array. I've searched around and I think I should start like this?

  $.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: ??
    }
});

How should I continue to get this data from the .php file into a Javascript array?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM