我有一個簡單ApiController我測試:jQuery的AJAX調用.NET網頁API返回錯誤
namespace SMOnline.Controllers
{
public class DocumentosController : ApiController
{
Documentos[] docs = new Documentos[]
{
new Documentos { ID = 1, Tipo = 1, Designacao = "FC001"},
new Documentos { ID = 2, Tipo = 1, Designacao = "FC002"}
};
public IEnumerable<Documentos> GetAll()
{
return docs;
}
}
}
而且在客戶端上我打的是不同的域調用此
$.ajax({
async: true,
type: 'GET', //GET or POST or PUT or DELETE verb
url: apiUrl + 'Documentos/', // Location of the service
dataType: 'jsonp', //Expected data format from server
})
.done(function (data) {
// On success, 'data' contains a list of documents.
$.each(data, function (key, item) {
alert(item.Designacao);
})
})
.fail(function (jqxhr, textStatus, error) {
alert(textStatus + " " + error);
});
我的問題是,JSONP請求返回永諾我一個錯誤
parsererror Error: jQuery20301899278084596997_1380125445432 was not called
我一直在尋找角落找尋,但還沒有找到了解決方案。
編輯: 我忘了提及使用fiddler返回的值看起來正確的標題是200和內容是一個JSON數組。
jsonp應該在服務器端進行處理。在服務器端你可以這樣做:'return「myCallBack(」+ data +「);」'? –
@RoyiNamir有無論如何,我可以知道什麼是在服務器端創建的自動回調值? – FabioG
請求[「callback」] –