WebAPI 在回调中使用 JSONP 错误

WebAPI using JSONP Error in callback

我有一个使用 JSONP nuget 包的 webapi,"WebApiContrib.Formatting.Jsonp"。

我已经尝试了 Global.asax 和以下三个声明:

GlobalConfiguration.Configuration.Formatters.Insert(0, new JsonpMediaTypeFormatter(new JsonMediaTypeFormatter()));

GlobalConfiguration.Configuration.AddJsonpFormatter();

var config = GlobalConfiguration.Configuration;   GlobalConfiguration.Configuration.AddJsonpFormatter(config.Formatters.JsonForma‌​tter, "callback");

当我通过在 URL 末尾添加 ?callback=Test 来测试回调时,它返回了 JSONP 对象,但它添加了一些前缀:

/**/ typeof Test === 'function' && 

我是不是做错了什么?谢谢

问题已通过使用 ajax 而不是 getJSON 解决。

function ajaxReq(url) {
    return jQuery.ajax({
        type: 'GET',
        dataType: 'jsonp',
        url: url
    })
}