“jquery-3.2.1.min.js:4 Access to XMLHttpRequest at 'https://******.xyz/api/WhatAppLink**.asmx/JaColak' from origin 'https://j.investluck.xyz' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.send @ jquery-3.2.1.min.js:4”。如下图:
此处报错已经提示:“access-control-allow-origin”,这里需要在服务端应用端配置access-control-allow-origin,加入Access-Control-Allow-Origin "*"。此跨域权限不限于.NET、jsp、PHP都有这个跨域设置,这里我们服务端采用.NET,所以在webconfig中配置相应设置,即开启了跨域权限,如下:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*"/>
<add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,OPTIONS"/>
<add name="Access-Control-Allow-Headers" value="Content-Type"/>
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>