ajax post 请求报错Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' heade
jquery ajax跨域请求,webapi webconfig配置
前台代码(放了一部分)
function CheckIn(roomno) {
$.ajax({
url: 'https://www..../RoomAssign',
type: 'post',
async: false,
contentType: 'application/json;charset=utf-8',
dataType: 'json',
data: JSON.stringify({
AccountId: localStorage.getItem("Accountid"),
Address: localStorage.getItem("Address"),
ArrivalDate: localStorage.getItem("Arrivaldate"),
Birthday: localStorage.getItem("Birthday"),
CertificateNo: localStorage.getItem("Certificateno"),
CertificateType: localStorage.getItem("Certificatetype"),
Country: localStorage.getItem("Country"),
})
后台代码:
public List<RoomAssign> RoomASSign([FromBody] RoomAssignIn model)
{
try
{
RoomAssignReq req = new RoomAssignReq();
req.AccountId = model.Accountid;
req.RoomNo = model.Roomno;
req.Rsvno = model.Rsvno;
RoomAssignRsp rsp = null;
ErrorInfo error = null;
List<RoomAssign> Rd = new List<RoomAssign>();
RoomAssign list = new RoomAssign();
if (db.RoomAssign(req, ref rsp, ref error) == )
{
list.resultcode = rsp.ResultCode;
list.description = rsp.Description; }
else
{
list.description = error.ErrorMessage;
}
Rd.Add(list);
return Rd;
}
catch (Exception ex)
{
throw ex;
} }
web配置以下内容
<system.web>
<!--提供Web服务访问方式-->
<webServices>
<protocols>
<add name="HttpSoap"/>
<add name="HttpPost"/>
<add name="HttpGet"/>
<add name="Documentation"/>
</protocols>
</webServices>
</system.web> <configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Methods" value="OPTIONS,POST,GET"/>
<add name="Access-Control-Allow-Headers" value="x-requested-with,content-type"/>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
<modules>
<add name="MyHttpModule" type="WebServiceDemo.MyHttpModule"/>
</modules>
</system.webServer>
</configuration>
如果报错:
未能加载类型“WebServiceDemo.MyHttpModule”。去掉
<modules>
<add name="MyHttpModule" type="WebServiceDemo.MyHttpModule"/>
</modules>
如果想选定的网站可能跨域访问,修改配置如下:
<add name="Access-Control-Allow-Origin" value="http://www....." />
ajax post 请求报错Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' heade的更多相关文章
- 跨域请求错误: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource
今天在学习Angular 的HttpInterceptor 拦截器时,发现添加了新的headers键值之后总是报跨域错误.后台使用的是asp.net core. 检查发现,在添加了新的header之后 ...
- Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' heade
XMLHttpRequest cannot load http://10.164.153.37:8050/WebService/WebService.asmx/wsGetStreetData. Res ...
- .Net Core 处理跨域问题Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource
网页请求报错: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Or ...
- has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
前端显示: has been blocked by CORS policy: Response to preflight request doesn't pass access control che ...
- Js 跨域CORS报错 Response for preflight has invalid HTTP status code 405
问题 公司项目H5调用接口遇到Response for preflight has invalid HTTP status code 405这样的错误,是使用PUT方式提交请求接口.Content-T ...
- ajax jsonp请求报错not a function的解决方案
概述 最近工作中使用ajax,有时会报json4 is not a function的错误,有时又不会报错.找了很久,网上说是因为多次请求同一个资源导致的,但是我检查了自己的代码,对于重复资源并没有重 ...
- 转 Js 跨域CORS报错 Response for preflight has invalid HTTP status code 405
转自:http://www.cnblogs.com/SilenceTom/p/6697484.html 调用接口遇到Response for preflight has invalid HTTP st ...
- 使用laravel框架开发接口时ajax post请求报错419
nginx服务器,使用laravel框架开发后台接口.get请求正常,但是post请求一直报错.H5和APP都不成功,code=419. 解决办法: 找到 VerifyCsrfToken.php文件( ...
- ajax post上传数据时,前端出现的跨域权限问题:ccess to XMLHttpRequest at ‘’rom origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok st
本人前端使用多个框架时,jq ajax传参出现如下报错: 最后发现,可能是xhr的相关默认参数被修改了.顾使用jq 传参时,一直报错,jq ajax额外添加的关键参数: crossDomain: ...
随机推荐
- Python网络爬虫(一):初步认识网络爬虫
不管你是因为什么原因想做一个网络爬虫,首先做的第一件事情就是要了解它. 在了解网络爬虫之前一定要牢记下面4个要点,这是做网络爬虫的基础: 1.抓取 py的urllib不一定去用.可是要学.假设你还没用 ...
- C#之选择排序
算法描述 1.假定未排序序列中第一位为数组最小值,通过与后面的数值进行比较,找到未排序序列中最小值,与未排序序列第一位交换位置: 2.重复步骤一,对剩余未排序序列进行比较找出最小值,与未排序序列中第一 ...
- UVa 489 Hangman Judge(字符串)
Hangman Judge In ``Hangman Judge,'' you are to write a program that judges a series of Hangman gam ...
- java中不能使用小数点(.)来作为分隔符
split()括号里是一个String的参数,所以一定要符合这种:split(".")形式,即点'.'要用双引号""括起来"."在java中 ...
- Android开发之策略模式初探
策略模式主要定义一系列的算法,学过数据结构的朋友肯定知道,对于数组从大到小进行排序有着非常多的算法.比方冒泡.交换.高速插入等等,策略模式就是把这些算法封装成一个个独立的类.方便使用时 ...
- 66.extjs 里对getvalue() 和getRawValue()
转自:https://blog.csdn.net/u014236541/article/details/49663589?locationNum=8
- Linux进程状态查询
进程状态详细说明 Linux进程状态详细解析 ps 的参数说明 ps 提供了很多的选项参数,常用的有以下几个: l 长格式输出: u 按用户名和启动时间的顺序来显示进程: ...
- Java 中数组的遍历方式
数组对于每一门编程语言来说都是重要的数据结构之一,当然不同语言对数组的实现及处理也不尽相同. Java 语言中提供的数组是用来存储固定大小的同类型元素. 今天我们就来说一下在java中遍历数组都有哪几 ...
- js将字符串中所有反斜杠\替换成正斜杠/
区分正斜杠与反斜杠: 正斜杠:http://.http紧跟着的斜杠,离手输入最近的斜杠,shift中间斜杠.45度角斜杠.正斜杠不需要转义 反斜杠:回车与空格之间.程序表示时需要转义成\\. str. ...
- 常用mysql记录
多个关键词 like$joinwhere .=" and CONCAT(`JpTel`,`JpName`) Like '%$keywords%' ";