JSON parsing using jQuery in API html link

I am trying to write a Jquery to Parse product information from an api.

<div id="placeholder"></div> script....

$.getJSON(data);
var output = "<ul>";
for (var i in data.products) {
output += "<li>" + data.products[i].sku + " " + data.products[i].name + "--" + 
data.products[i].salePrice + "</li>";
}
output += "</ul>";
document.getElementById("placeholder").innerHTML = output;`

when I give var data = {"products":[{"id_item":12324,"id_name":"canon"} it works but if I pass a link var data = "http://api.remix.bestbuy.com/v1/products(manufacturer=canon&salePrice%3C1000)?format=json&show=sku,name,salePrice&apiKey=<API_KEY> it does not work. I am a beginner and trying to learn JQUERY. Any kind of help will be appreciated...Is there any code debugger for Jquery... Thanks in advance...

Answers


If you're setting the variable data for a URL and using that in the getJSON function then your data.products etc.. is not actually referencing anything because data is still pointing at your URL.

Take a look at the getJSON API Documentation but you'll need to do something like the below.

var url = "http://api.remix.bestbu....."
$.getJSON(url, function(data){
   var output = "<ul>";
   for (var i in data.products) {
      etc.....
});

EDIT

For JSONP you will need to specify the data type using the $.ajax function. I'm not aware of a way doing it with $.getJSON, someone correct me please if I;m wrong.

$.ajax({
   type:"GET",
   dataType: "JSONP",
   url: url,
   success:function(data){
      // .... Your function with the data. 
   }
});

Need Your Help

Convert FileUpload to X509Certificate2

c# file-upload encryption certificate digital-certificate

How can I convert an uploaded file to an X509Certificate2 variable?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.