前言
做了一个简单页面,做了一些数据埋点,想通过企业微信机器人来推送数据,遇到了一些问题,顺便记录下。
跨域问题的解决思路
由于是项目比较简单,直接使用了ajax去请求,代码如下
$.ajax({
type: 'POST',
url: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=b38aa4d8-a08e-4a91-',
async: true,
data: $.toJSON(data),
contentType:'application/json;charset=utf-8',
dataType: 'json',
success: function (data) {
console.log("data",data)
},
error: function (error) {
console.log("error",error);
}
})
请求的时候发现了跨域问题
Access to XMLHttpRequest at 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=b38aa4d8-a08e-4a91-' from origin 'null' 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.