jQuery的POST请求实际发送的GET [英] jQuery POST request actually sends as GET

查看:228
本文介绍了jQuery的POST请求实际发送的GET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用下面的code发送POST请求:

I'm trying to use the following code to send a POST request:

$.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请求?

However, this always goes through as a GET request, not a POST request, and the API server consequently rejects it. Why is jQuery insisting on making this a GET request?

(这是故意跨域的,但它的JSONP所以这不是一个问题。)

(This is intentionally cross-domain, but it's JSONP so that's not a problem.)

推荐答案

JSONP是一个GET只有这么数据类型:JSONP,将永远是一个GET

JSONP is a GET only so dataType: 'jsonp', will always be a get

想想JSONP的是这样的:

Think of JSONP like this:

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

由于这是多么JSONP获取解决跨域,它只能是一个GET请求。

Since that's how jsonp gets around cross-domain, it can only be a get request.

这篇关于jQuery的POST请求实际发送的GET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆