Upon receiving a JSON response from the Amazon API, here is how it appears:
{
"Result": {
"Data": {
"Title": "HALO 3 (XBOX 360 - REGION FREE)",
"FormattedPrice": "$19.95",
"Source": "Product Description",
"Content": "The epic saga continues..."
}
}
}
Despite my efforts, I keep encountering 'undefined' in my Javascript code when attempting to access FormattedPrice.
I've attempted different versions like:
var price1 = Response.Result.Data.FormattedPrice;
var price1 = Response.Result[0].Data[0].FormattedPrice;
var price1 = Response.Result[0].FormattedPrice;
Here is the modified full call code:
The data name has been changed to Halo 3 and 'Response' now stands as PriceResponse
//Load Amazon Price data
var setUrl = "https://example.com/price.php?q="+encodeURI(data.name)+"&output=json";
console.log(setUrl);
jQuery.getJSON(setUrl, function(priceResponse) {
var price1 = Response.Result[0].Data[0].FormattedPrice;
jQuery("#info-link-amazon").append('<span style="float:right;">$'+price1+'</span>');
});