2013-03-07 54 views
1

我懷疑這是因爲我沒有返回可以解析的JSON。下面是一個示例:

Response.ContentType = "application/json"; 
Response.Write(JsonConvert.SerializeObject(new {foo="bar"})); 

鉻告訴我下面......「未捕獲的SyntaxError:意外的標記:」

這種方法產生同樣的反應:

return Json(new {foo="bar"}, JsonRequestBehavior.AllowGet); 

我在做什麼錯誤?此外,這是一個跨域請求。

$.ajax({ 
     url: myURL, 
     type: 'GET', 
     async: true, 
     dataType: 'jsonp', 
     cache: false, 
     success: function (data) { 
      alert(data); 
     } 
    }); 

編輯:這裏是JSON C#吐出:

{"foo":"bar"} 

回答

2

我認爲,這是因爲通過的dataType預期的jQuery是設置於JSONP,但是你不回JSONP。將其更改爲json或甚至使用:

$.get(myUrl, { cache: false }).done(function (data) { 
    alert(data); 
}); 
相關問題