There has been a circular redirection when developing Wechat's official account. What's going on?

God help me to see why this cannot be entered into the success function all the time. It has been alert (login failure), and it is circular. Because it cannot enter the success, it cannot save cookie, so it has been redirected and crashed

.
let bind = Cookies.get("ptoken")
if (bind == undefined) {
  location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd36b3798a2beb820&redirect_uri=http://testwechat.hotol.cn/dak/index.html&response_type=code&scope=snsapi_userinfo&state=1-sharpwechat_redirect";

let json = {
  code:"001WYYaG1ffLF1038WdG1c81bG1WYYaa"
};
let url = location.hostname;
wx_login(json,function (res) {
  console.log(res);
  location.href = "http://" + url + "/dak/";
})
function wx_login(data, completion) {
  let time = Date.parse(new Date());
  let hash = hex_md5(time + "XXX");
  $.ajax({
    type: "post",
    url: "192.168.18.85:8080/weChatUserLogin",
    data: JSON.stringify(data),
    async: false,
    dataType: "text",
    headers: {
      "token": "",
      "version": "1",
      "client_type": "3",
      "Timestamp": time,
      "SignInfo": hash,
      "Access-Control-Allow-Origin": "*",
    },
    contentType: "application/json;charset=UTF-8",
    success: function (res) {
      res = JSON.parse(res);
      Cookies.set("ptoken","wwwww");
      console.log(res);
      if (res.code == 0) { //
        console.log(res);

      } else {
        console.log(res.message);
      }
    },
    error: function () {
      alert("");
    }
  })
}
}
Feb.26,2021

1. Non-stop loop is that you started location.href to do Wechat login authorization jump, and the target page should be this page, then ajax success has not responded, 'ptoken' this how can there be value, naturally keep jumping. Protocol https:// is added to
2.ajax url, and http://
3.ajax data does not need to be converted into a string, even in get mode.
4. Completion did not call
5 in your wx_login. Let the server send back the json format. Change it to dataType:'JSON', so that you don't need JSON.parse (res) to convert
6.res.code = = 0. If you want to use the operation =
7.Cookies.set ('ptoken','wwwww'), you must put it within the condition of successful login. Otherwise, if you save it into undefined, and withdraw it as' undefined', this is a logic problem
8. In the login authorization, the redirect_uri part needs to be transcoded

the general process logic is as follows:

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b2c500-2a84a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b2c500-2a84a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?