I am trying to return multiple values from a php process.
Here is the jQuery function
$.ajax({
url: 'shopping_cart_add.php',
data: 'item_id='+subscription_id+'&item_name='+subscription_name+'&item_price='+subscription_price,
type: 'POST',
dataType: 'json',
success: function(response, statusText) {
var qty = response.item_quantity;
$("#shopping-cart-quantity").html(qty);
}
});
The above seems to work except I can't retrieve the specific field values from the returned JSON.
When I try this...
var qty = response.item_quantity;
$("#shopping-cart-quantity").html(qty);
Nothing happens.
If I change...
$("#shopping-cart-quantity").html(qty);
to
$("#shopping-cart-quantity").html(response);
I get the following...
{ 'account_id': '1', 'item_id' : 'cce3d2a017f6f1870ce8480a32506bed', 'item_name' : 'CE', 'item_quantity' : '1', 'item_price' : '1' }
responsehave aresponseJSONproperty that has the object you're looking for?dataType: 'json',responseis already parsed, it's not the XHR.json_encode()to encode the response.