| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- /**
- * 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",
- // extends: cc.Component,
- //
- // properties: {
- // // foo: {
- // // default: null, // The default value will be used only when the component attaching
- // // to a node for the first time
- // // url: cc.Texture2D, // optional, default is typeof default
- // // serializable: true, // optional, default is true
- // // visible: true, // optional, default is true
- // // displayName: 'Foo', // optional
- // // readonly: false, // optional, default is false
- // // },
- // // ...
- // },
- //
- // statics: {
- // instance: null
- // },
- // use this for initialization
- onLoad: function () {
- },
- // get: function (url, callbackSuccess,callbackFail) {
- // var xhr = cc.loader.getXMLHttpRequest();
- //
- // cc.log("调用了吗 请求");
- // xhr.onreadystatechange = function () {
- // if (xhr.readyState === 4 && (xhr.status >= 200 && xhr.status < 300)) {
- // var respone = xhr.responseText;
- // callbackSuccess(respone);
- // }else{
- // callbackFail();
- // }
- // }.bind(this);
- // xhr.open("GET", url, true);
- // if (cc.sys.isNative) {
- // xhr.setRequestHeader("Accept-Encoding", "gzip,deflate");
- // }
- //
- // // note: In Internet Explorer, the timeout property may be set only after calling the open()
- // // method and before calling the send() method.
- // xhr.timeout = 5000;// 5 seconds for timeout
- //
- // xhr.send();
- // },
- 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"
- },
- //
- // post: function (url, params, callbackSuccess,callbackFail) {
- // var xhr = cc.loader.getXMLHttpRequest();
- // xhr.onreadystatechange = function () {
- // cc.log('xhr.readyState='+xhr.readyState+' xhr.status='+xhr.status);
- // if (xhr.readyState === 4 && (xhr.status >= 200 && xhr.status < 300)) {
- // var respone = xhr.responseText;
- // callbackSuccess(respone);
- // }else{
- // callbackFail();
- // }
- // }.bind(this);
- // xhr.open("POST", url, true);
- // if (cc.sys.isNative) {
- // xhr.setRequestHeader("Accept-Encoding", "gzip,deflate");
- // }
- //
- // // note: In Internet Explorer, the timeout property may be set only after calling the open()
- // // method and before calling the send() method.
- // xhr.timeout = 5000;// 5 seconds for timeout
- //
- // xhr.send(params);
- // }
- };
- // httpUtils.getInstance = function () {
- // if (httpUtils.instance == null) {
- // httpUtils.instance = new httpUtils();
- // }
- // return httpUtils.instance;
- // };
- // module.exports = httpUtils;
|