我無法解析此api。你能看到我做了什麼嗎?api的jquery解析響應bbyopen
PHP的捲曲呼叫:
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
$options = array(CURLOPT_URL => 'http://api.remix.bestbuy.com/v1/products(salePrice<='.$dollars.'&type=Music)?apiKey=gzunxsecretsdssf444&format=json&show=name,salePrice,shortDescription,image',
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => 1
);
curl_setopt_array($ch, $options);
// grab URL and pass it to the browser
echo curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
的JS:
$.ajax({
url: "./file.php",
type: 'GET',
dataType: 'JSON',
success: function (data) {
console.log("Success");
console.log(data);
for(var i=0;i<=data.products.length;i++)
{
var thumb=data.products[i].image;
$('<div class="product" style="background-color:green"><a href=""><img src="'+ thumb +'" alt""/></a></div>').appendTo('#find_stuff_div');
}
}
});
變種拇指= data.products [I]圖像配;是我遇到麻煩的地方。對象本身記錄(顯然是json),但是var thumb返回「Uncaught TypeError:無法讀取未定義的屬性'圖像'。有任何想法嗎?
控制檯登錄
是什麼'data.products'是一個數組 – 2013-03-21 03:07:00
還添加了一個'console.log(data.products,data.products.length)' – 2013-03-21 03:07:24
我從控制檯上面添加了結果 – CaitlinHavener 2013-03-21 03:12:57