Reputation: 12685
I've got an ajax call via jquery that executes without error until I get to the callback. The content returned looks like this:
{"UPSELLABLE":true,"OFFERTEXT":"p47r.cfm"}
Simply doing alert(upselldata); will alert the data above. But if I try access variable upselldata like a javascript object( I thought jquery did the eval work for me already ), the variables are undefined. See code below:
$.ajax({
type: "POST",
datatype: "json",
data: "ProductID=1",
url: '/templates/public/upsell_available.cfm',
success: function(upselldata) {
alert(upselldata.UPSELLABLE); // upselldata.upsellable is undefined!?!?!
}
});
Upvotes: 0
Views: 303
Reputation: 4170
Use "dataType" not "datatype". Javascript is case-sensitive, therefore, jQuery is ignoring your setting.
Note that jQuery can auto-detect the type of data if you set the the headers properly in the response (I assume you are sending it back as text).
Upvotes: 2