views:

22

answers:

1

I have the following JSON coming back:

{"gameId":137.0,"memberId":3,"id":97.0,"reviewBody":"Great game! Awesome.","createdAt":"October, 13 2010 18:55:34"}

I'm trying to append it to a layer using the following JavaScript, but nothing is showing:

$(function(){
    $(".review-form").submit(function(){
        dataString = $(".review-form").serialize();
        $.ajax({ 
            type: "POST", 
            url: "#URLFor(controller="membros", action="createReview")#",
            data: dataString,
            dataType: "JSON",
            returnFormat: "JSON",
            success: function(response) { 
                $(".review-confirmation").html(response.REVIEWBODY);
                $('.review-form').slideToggle('slow', function() { });
            } 
        });
        return false; // keeps the normal request from firing
    });
});

I've tried using uppercase, lowercase, and camel-case for response.reviewBody, but nothing was showing. Any ideas where I'm going wrong?

+2  A: 

Surprisingly,

dataType: "JSON",

in upper case will not return JSON data.

You need to use

dataType: "json",
Pekka
Surprisingly? lol!
Quickredfox
@Quickredfox where on the [manual page](http://api.jquery.com/jQuery.ajax/) do you see this behaviour documented? I find it highly surprising, especially in light of ` If none is specified, jQuery will intelligently try to get the results, based on the MIME type of the response`
Pekka
Not disagreeing, admiring your choice of words.
Quickredfox