我如何訪問通過ajax請求發佈在我的PHP數據。我的ajax請求正在返回一串數據,但我似乎無法訪問作爲json對象傳遞的變量。我如何訪問只包含一個參數的json對象。PHP獲取訪問張貼在阿賈克斯請求的ID
的jQuery:
$.ajax({
type:'POST',
url:"../../webservices/get_rating.php",
data:JSON.stringify({product_id:id}),
dataType:"html",
success: function(data) {
$('.ratings-content').append(data);
}, error:function(data, status, xhr) {
alert(data + "\r\n" + status + "\r\n" + xhr);
}
});
,並在我的PHP代碼,它的這個讓我的product_id不工作
PHP:
$product_id = (int)$_POST["product_id"];
echo $product_id; always returns 0
你是什麼意思「它不工作?」 – esqew 2013-04-18 03:47:16
你在那裏看起來對我來說是正確的。你看過請求標題嗎? – 2013-04-18 03:47:30
你是什麼意思請求標題是什麼? – ONYX 2013-04-18 03:48:11