2

我有以下 jQuery 代码:

    $.ajax({
        url: Url,
        dataType: 'JSONP',
        type: 'POST',
        success: function (data, textStatus, jqXHR) {
            //callback function here
        },
        error: function (xhr, ajaxOptions, thrownError) {
            //report error
        }
    });

但是,当我在Fiddler中查看此 AJAX 请求时,我的请求已从 a 转换POST为 a GET

我正在连接的 API 不允许这样做,因为它必须是POST请求。

为什么会这样?

4

3 回答 3

8

JSONP 请求只能是 GET。

删除dataType: 'JSONP'.

于 2012-10-23T15:24:07.610 回答
1
dataType: 'JSONP', 

始终是GET请求

于 2012-10-23T15:25:30.497 回答
1

您不能将 POST 与 JSONP 一起使用,请参阅https://groups.google.com/forum/?fromgroups=#!topic/jquery-dev/5-tKI-7zQvs了解更多详情。

于 2012-10-23T15:28:05.737 回答