用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中了。

 

posted on 2017-03-17 11:51  半夏微澜ぺ  阅读(9784)  评论(0编辑  收藏  举报