How to make a jsonp POST request that specifies contentType with jQuery?

Marcus picture Marcus · Oct 5, 2010 · Viewed 38.4k times · Source

I need to make a jsonp POST request with the content type 'application/json'. I can get the POST request to the server like this:

      jQuery.ajax({
        type: 'POST',
        url: url,
        data: data,
        success: success,
        error: error,
        async: true,
        complete: complete,
        timeout: TIMEOUT,
        scriptCharset: 'UTF-8',
        dataType: 'jsonp',
        jsonp: '_jsonp',
      });

But as soon as I add the line:contentType: "application/json" it starts sending it as an OPTIONS request rather than a POST.

How can I specify the content type and still submit the request as a POST?

Answer

SLaks picture SLaks · Oct 5, 2010

It is not possible to make a JSONP POST request.

JSONP works by creating a <script> tag that executes Javascript from a different domain; it is not possible to send a POST request using a <script> tag.