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的更多相关文章

  1. 跨域请求错误: 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之后 ...

  2. 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 ...

  3. .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 ...

  4. 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 ...

  5. Js 跨域CORS报错 Response for preflight has invalid HTTP status code 405

    问题 公司项目H5调用接口遇到Response for preflight has invalid HTTP status code 405这样的错误,是使用PUT方式提交请求接口.Content-T ...

  6. ajax jsonp请求报错not a function的解决方案

    概述 最近工作中使用ajax,有时会报json4 is not a function的错误,有时又不会报错.找了很久,网上说是因为多次请求同一个资源导致的,但是我检查了自己的代码,对于重复资源并没有重 ...

  7. 转 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 ...

  8. 使用laravel框架开发接口时ajax post请求报错419

    nginx服务器,使用laravel框架开发后台接口.get请求正常,但是post请求一直报错.H5和APP都不成功,code=419. 解决办法: 找到 VerifyCsrfToken.php文件( ...

  9. 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: ...

随机推荐

  1. hadoop-2.6.0 Unhealthy Nodes 问题

    近期安装hadoop-2.6.0集群时,打开8088页面,查看集群信息,看到集群出现Unhealthy Nodes 的问题,点击该处.会展开Unhealthy Nodes 的情况,这时会看到Healt ...

  2. 数据库学习之简单的SQL语句

    1.数据库的结构 1.1数据库 不同数据库叫做Catalog(在有的 DBMS 中也称为 Database,即数据库) .採用多 Catalog 以后能够给我们带 来例如以下优点: 便于对各个 Cat ...

  3. Python&amp;MySQL

    环境:windows8+Python2.7+MySQL5.6 尝试过在C/C++中嵌入SQL语言,最终在其复杂"繁琐"环境配置中败下阵来,后来发现Python和MySQL比較eas ...

  4. linux驱动之设备号与创建设备节点

    设备号: 1.自己主动分配 major = register_chrdev(0,"first_drv",&first_sdv_fops);//注冊 注冊设备时给设备号写0, ...

  5. 字节数组byte[]和整型,浮点型数据的转换——Java代码

    近期在写C++ socket和java socket之间的通信程序,涉及到整数浮点数的传输.须要从字节数组还原数据,查了一些资料.总结例如以下 1.       整数和浮点数的机器表示 在机器内部.不 ...

  6. sql server的版本检查

    https://support.microsoft.com/en-ph/help/321185/how-to-determine-the-version-edition-and-update-leve ...

  7. Bing Maps进阶系列三:使用地图图像服务(ImageryService)

    Bing Maps进阶系列三:使用地图图像服务(ImageryService) 地图图像服务(ImageryService)提供了根据地理位置(经度和纬度)坐标和地图的缩放级别解析出对应于地图图片系统 ...

  8. 洛谷 P2055 [ ZJOI 2009 ] 假期的宿舍 —— 二分图匹配

    题目:https://www.luogu.org/problemnew/show/P2055 二分图匹配: 注意要连边的话对方必须有床! 代码如下: #include<iostream> ...

  9. Django-CKeditor使用笔记

    1. 安装django-ckeditor $ pip install django-ckeditor 2. 在setting中,添加ckeditor , ckeditor_uploader 到INST ...

  10. B. Trees in a Row(cf)

    B. Trees in a Row time limit per test 1 second memory limit per test 256 megabytes input standard in ...