AJAX POST request working in POSTMAN but not in Chrome(AJAX POST 请求在 POSTMAN 中有效,但在 Chrome 中无效)
问题描述
我正在尝试发出一个简单的 AJAX POST 请求.在 POSTMAN 中执行此请求时工作正常.但是,当我在 jQuery 中对其进行编码并尝试发出相同的请求时,我得到了
I am trying to make a simple AJAX POST request. This request when executed in POSTMAN works fine. However, when I code it in jQuery and try to make the same request, I get
请求的资源上不存在Access-Control-Allow-Origin"标头.因此,Origin 'file://' 不允许访问.响应的 HTTP 状态代码为 415.
现在,我必须发出一个 POST 请求,因此在请求中使用 JSONP 作为类型将无济于事.我无权访问服务器代码来修改它.我的基本理解是,如果POSTMAN可以执行,那么我应该也可以执行
Now, I have to make a POST request and hence using JSONP as type in the request won't help. I do not have access to server code to modify it. My basic understanding is that if POSTMAN can execute it, then i should be able to do it as well
推荐答案
状态码一目了然.415
当您发送不受支持的内容类型(例如 xml)时,它会从服务器返回.仔细检查您在代码中传递给发布请求的数据类型.
the status code is self explanatory.
415
it's returned from the server when you sent an unsupported content type (e.g. an xml). double check the type of data you're passing to the post request in your code.
415 UNSUPPORTED MEDIA TYPE 源服务器拒绝服务请求,因为有效负载的格式不受此支持目标资源上的方法.
415 UNSUPPORTED MEDIA TYPE The origin server is refusing to service the request because the payload is in a format not supported by this method on the target resource.
格式问题可能是由于请求的指示Content-Type 或 Content-Encoding,或作为检查的结果直接数据.
The format problem might be due to the request's indicated Content-Type or Content-Encoding, or as a result of inspecting the data directly.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/415
这篇关于AJAX POST 请求在 POSTMAN 中有效,但在 Chrome 中无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:AJAX POST 请求在 POSTMAN 中有效,但在 Chrome 中无效


基础教程推荐
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01