代码之家  ›  专栏  ›  技术社区  ›  Mohamad

无法在JSON中追加返回的内容

  •  0
  • Mohamad  · 技术社区  · 14 年前

    我有以下JSON返回:

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

    我正在尝试使用以下javascript将其附加到一个层,但没有显示任何内容:

    $(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
        });
    });
    

    我已经尝试使用大写、小写和驼色大小写来响应.reviewBody,但没有显示任何内容。知道我哪里出错了吗?

    1 回复  |  直到 14 年前
        1
  •  2
  •   Pekka    14 年前

    令人惊讶的是,

    dataType: "JSON",
    

    在上例中,不会返回JSON数据。

    你需要使用

    dataType: "json",