Reputation: 5859
How do I get access to the data that's been posted via ajax request in my php. My ajax request is working to return a string of data but I can't seem to access the variable thats being passed as a json object. What do I to access a json object that only contains one parameter.
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);
}
});
and in my php code its this to get my product_id which doesn't work
PHP:
$product_id = (int)$_POST["product_id"];
echo $product_id; always returns 0
Upvotes: 0
Views: 164
Reputation: 1013
the default for ajax is $_GET so rither specify POST at the ajax end or use GET on the server side
Upvotes: 0