我有一个简单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”] –