用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