如何使用 jQuery 发出指定 contentType 的 jsonp POST 请求? [英] How to make a jsonp POST request that specifies contentType with jQuery?

查看:61
本文介绍了如何使用 jQuery 发出指定 contentType 的 jsonp POST 请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用内容类型application/json"进行 jsonp POST 请求.我可以像这样将 POST 请求发送到服务器:

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',
      });

但是一旦我添加了以下行:contentType: "application/json" 它就开始将它作为 OPTIONS 请求而不是 POST 发送.

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

如何指定内容类型并仍将请求作为 POST 提交?

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

推荐答案

无法发出 JSONP POST 请求.

It is not possible to make a JSONP POST request.

JSONP 通过创建一个

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