WebService设置以下允许跨域请求
<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>
</system.webServer>
前端http调用
ttp.post('xxx[跨域链接,eg:https://www.baidu.com]', {
username:"",
emailadress:"",
},{
headers: {
//webservice请求是通过www-form形式
"Content-Type": "application/x-www-form-urlencoded"
},
}, "正在註冊") .then(function(res) {
// 连接成功后的回调函数
console.log("连接成功");
console.log(res);
})
.catch(function(err) {
// 连接失败后的回调函数
console.log("连接失败" + err);
});
}