views:

39

answers:

1

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!?!?!
         }
        });
+2  A: 

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).

Johnco
Haha, bingo. Good eye.
Darthg8r
+1 I never knew the basic jQuery call returned a JavaScript Object
Damien