2012-07-24 32 views
0

我寫了下面的Javascript,但得到錯誤'無效的JSON原語:strSeason'。其餘的語法看起來不錯,但我似乎無法得到正確的'數據'參數。任何人都可以幫助我的語法?C#中的JSON語法#

TagBuilder script = new TagBuilder("script"); 
      script.Attributes.Add("type", "text/javascript"); 
      script.Attributes.Add("language", "javascript"); 
      // ReSharper disable LocalizableElement 
      script.InnerHtml = @" 

      $.ajax({ 
       type: 'POST', 
       async: true, 
       contentType: 'application/json; charset=utf-8', 
       dataType: 'html', 
       url: '/en-US/" + areaName + '/' + controllerName + '/' + actionName + @"', 
       data: " + "{strSeason:'" + season + "', strTeam:'" + team + @"'}, 
       beforeSend: function(xhr){ 
       $(this).addClass('ajaxRefreshing'); 
       xhr.setRequestHeader('X-Client', 'jQuery'); 
       }, 
       success: function(html){ 
       $(this).html(html); 
       }, 
       complete: function(){ 
       $(this).removeClass('ajaxRefreshing'); 
       } 
      }); 

     "; 
+0

你可以驗證你的json字符串http://jsonlint.com – 2012-07-24 08:49:39

+0

不應該數據類型是「json」嗎? – Steve 2012-07-24 08:51:35

回答

0

包的名稱在引號

data: " + "{'strSeason':'" + season + "', 'strTeam':'" + team + @"'}, 

編輯:您可能只需要發送的JSON字符串,以便包住整個字符串加引號。

data: " + "\"{'strSeason':'" + season + "', 'strTeam':'" + team + "'}\"" [email protected]", 
+0

嘗試過,它給出了同樣的錯誤 – user517406 2012-07-24 08:39:21

+0

@ user517406更新了新的編輯 – 2012-07-24 08:47:55