用js获取access_token


尝试用js获取access_token 最终失败告终,哈哈

1需要 appId和AppSecret 这两个参数是要保密的,建议不要暴露在外面,以防被别有用心的人利用。

$.ajax({
                url:'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=appid&secret=secret',
                type:"get",
                async: true,
                success: function (result) {
                   
                },
                error: function (result) {
                    console.log(result);
                }
            });

Ajax跨域请求报错:XMLHttpRequest cannot load ''. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' ' is therefore not allowed access

但是可以在network中查看到返回值,只是ajax不走success ,调到error中了。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM