jQuery的POST请求实际上发送为GET请求

5
我将尝试使用以下代码发送POST请求:

我正在尝试使用以下代码发送POST请求:

$.ajax({
    type: "post",
    url: 'http://api.com/'+apiUsername+'/'+apiBucket+'/elements/add',
    dataType: 'jsonp',
    contentType: "application/json",
    data: JSON.stringify({
        username: apiUsername,
        api_key: APIkey,
        elementPermalink: tURL
    }),
    success: function() {
        console.log('posted!');
    }
});

然而,这始终作为GET请求进行,而不是POST请求,因此API服务器拒绝它。为什么jQuery坚持将其作为GET请求?
(这是有意的跨域,但它是JSONP,所以没有问题。)
1个回答

20

JSONP只支持GET请求,因此dataType: 'jsonp'始终是GET请求。

可以这样理解JSONP:

<script src="http://url.com/?query=string"></script>

因为这就是jsonp绕过跨域的方式,所以它只能是一个get请求。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接