My service returns the following JSON object, with the Content-Type header set to "application/javascript". It's wrapped in parens per instructions at json.org][2], but I've tried with and without parens. Without parens, it passes verification from jsonlint.
({"products": {"itemId": "0", "productId": "1234", "quantity": "4", "rank": "12", "subProductId": ""}, "txnId": "1"})
If I explicitly eval the response, as shown below, I have no problem:
var form = $('productListRequestForm');
form.request(
{
onSuccess :
function(response)
{
var json = eval(response.responseText);
rebuildWishlistTable(json);
},
onFailure :
function(response)
{
alert("AJAX request failed: " + response.responseText);
}
});
However, if I rely on Prototype parsing the response and passing the parsed result as a second parameter to my function as below, that value is always null. According to the Prototype docs, this should work. Is there something that I'm missing, or something that they're missing?
var form = $('productListRequestForm');
form.request(
{
onSuccess : function(response, json)
{
rebuildWishlistTable(json);
},
onFailure :
function(response)
{
alert("AJAX request failed: " + response.responseText);
}
});