The jQuery POST request is actually sent as a GET

I am 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!');
    }
});

However, this always passes as a GET request, not a POST request, and the API server therefore rejects it. Why does jQuery insist on making this GET request?

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

+5
source share
1 answer

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

Think of JSONP as follows:

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

Since jsonp traverses the cross-domain, it can only be a receive request.

+20
source

All Articles