/** * Created by MSIK on 2018/12/22. */ window.userData = { httpData : { data: { avatarUrl: "/media/img/oGxOa5SQ1ltBWWsVRirUvXUBGRRY.png", city: "Harbin", gender: 1, nickName: "汪汪Husky", openid: "oGxOa5SQ1ltBWWsVRirUvXUBGRRY", province: "Heilongjiang" }, }, // oGxOa5bd61v9jI_indIdQtI2T5P8 大佬 // oGxOa5bjKLaCSbkPev09yVze0WSA 晓明 // oGxOa5del9BkzJ3e8fLVzI4mlvEI 小狐仙 // oGxOa5eZUuWCNCoEUQIjtu2uN9BM 9527 // oGxOa5SQ1ltBWWsVRirUvXUBGRRY 汪汪 openId: "oGxOa5bjKLaCSbkPev09yVze0WSA" } window.httpUtils = { http : "https://www.yuyekeji.cn/", setUserData : "https://www.yuyekeji.cn/Iamrichman_app/setUserData/", // setUserData : "https://www.youaigclm.top/Iamrichman_app/setUserData/", // getUserData : "https://www.youaigclm.top/api/getJson", getUserData : "https://www.yuyekeji.cn/Iamrichman_app/getUserData/", // getUserData : "https://www.youaigclm.top/Iamrichman_app/getUserData/", PlayButton : "https://www.youaigclm.top/media/PlayButtonnew.png", Share : "https://www.youaigclm.top/media/Share.png", Get: function(url,reqData,callbackSuccess,callbackFail){ var self = this; url += "?"; for(var item in reqData){ url += item +"=" +reqData[item] +"&"; } // console.log(self.ip + url) var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { if (xhr.readyState == 4){ if(xhr.status >= 200 && xhr.status < 400){ var response = xhr.responseText; // console.log(response) if(response){ var responseJson = JSON.parse(response); callbackSuccess(responseJson); }else{ // console.log("返回数据不存在") callbackFail(); } }else{ // console.log("请求失败") callbackFail(); } } }; xhr.open("GET", url, true); xhr.send(); }, /** * var data = []; * data["img"] = httpImag; * @param url * @param reqData * @param callbackSuccess * @param callbackFail * @constructor */ Post: function (url, reqData, callbackSuccess,callbackFail) { var self = this; // console.log(url) // console.log(reqData) //1.拼接请求参数 var param = ""; for(var item in reqData){ param += item + "=" + reqData[item] + "&"; } //2.发起请求 var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { if (xhr.readyState == 4){ if(xhr.status >= 200 && xhr.status < 400){ var response = xhr.responseText; // console.log(response) if(response){ var responseJson = JSON.parse(response); callbackSuccess(responseJson); }else{ // console.log("返回数据不存在") callbackFail(); } }else{ // console.log("请求失败") callbackFail(false); } } }; xhr.open("POST", url, true); xhr.setRequestHeader("Content-Type" , "application/x-www-form-urlencoded"); xhr.send(param);//reqData为字符串形式: "key=value" }, };