2010-10-13 48 views
0

我有以下的JSON回來:無法附加內容回來的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 
    }); 
}); 

我已經嘗試使用大寫,小寫和駱駝案件response.reviewBody,但沒有任何顯示。任何想法,我要去錯了嗎?

+2

基本調試。 alert(response.reviewBody);'說什麼? – 2010-10-13 22:08:05

+0

它說「未定義!」 :/ – Mohamad 2010-10-13 22:10:38

+0

但「響應」顯示整個JSON字符串... – Mohamad 2010-10-13 22:11:22

回答

2

出人意料的是,

dataType: "JSON", 

以大寫字母將不會返回JSON數據。

首先,您需要使用

dataType: "json", 
+0

出人意料?大聲笑! – Quickredfox 2010-10-13 23:27:58

+0

@Quickredfox您在[手冊頁](http://api.jquery.com/jQuery.ajax/)上的哪個地方看到了此行爲記錄?我發現它非常令人吃驚,尤其是如果沒有指定,jQuery將根據響應的MIME類型智能地嘗試獲得結果。 – 2010-10-14 08:16:15

+0

不反對,欣賞您選擇的單詞。 – Quickredfox 2010-10-14 22:21:01