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