国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

Cocos Creator JS http通信封裝

2022-05-21 12:18 作者:Nimanggi  | 我要投稿


/**
 * Http 請求封裝
 */
const HttpHelper = cc.Class({
 ? ?extends: cc.Component,

 ? ?statics: {
 ? ?},

 ? ?properties: {

 ? ?},

 ? ?/**
 ? ? * get請求
 ? ? * @param {string} url 
 ? ? * @param {function} callback 
 ? ? */
 ? ?httpGet(url, callback) {
 ? ? ? ?cc.myGame.gameUi.onShowLockScreen();
 ? ? ? ?let xhr = cc.loader.getXMLHttpRequest();
 ? ? ? ?xhr.onreadystatechange = function () {
 ? ? ? ? ? ?// cc.log("Get: readyState:" + xhr.readyState + " status:" + xhr.status);
 ? ? ? ? ? ?if (xhr.readyState === 4 && xhr.status == 200) {
 ? ? ? ? ? ? ? ?let respone = xhr.responseText;
 ? ? ? ? ? ? ? ?let rsp = JSON.parse(respone);
 ? ? ? ? ? ? ? ?cc.myGame.gameUi.onHideLockScreen();
 ? ? ? ? ? ? ? ?callback(rsp);
 ? ? ? ? ? ?} else if (xhr.readyState === 4 && xhr.status == 401) {
 ? ? ? ? ? ? ? ?cc.myGame.gameUi.onHideLockScreen();
 ? ? ? ? ? ? ? ?callback({status:401});
 ? ? ? ? ? ?} else {
 ? ? ? ? ? ? ? ?//callback(-1);
 ? ? ? ? ? ?}


 ? ? ? ?};
 ? ? ? ?xhr.withCredentials = true;
 ? ? ? ?xhr.open('GET', url, true);

 ? ? ? ?// if (cc.sys.isNative) {
 ? ? ? ?xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
 ? ? ? ?xhr.setRequestHeader('Access-Control-Allow-Methods', 'GET, POST');
 ? ? ? ?xhr.setRequestHeader('Access-Control-Allow-Headers', 'x-requested-with,content-type,authorization');
 ? ? ? ?xhr.setRequestHeader("Content-Type", "application/json");
 ? ? ? ?xhr.setRequestHeader('Authorization', 'Bearer ' + cc.myGame.gameManager.getToken());
 ? ? ? ?// xhr.setRequestHeader('Authorization', 'Bearer ' + "");
 ? ? ? ?// }

 ? ? ? ?// note: In Internet Explorer, the timeout property may be set only after calling the open()
 ? ? ? ?// method and before calling the send() method.
 ? ? ? ?xhr.timeout = 8000;// 8 seconds for timeout

 ? ? ? ?xhr.send();
 ? ?},

 ? ?/**
 ? ? * post請求
 ? ? * @param {string} url 
 ? ? * @param {object} params 
 ? ? * @param {function} callback 
 ? ? */
 ? ?httpPost(url, params, callback) {
 ? ? ? ?cc.myGame.gameUi.onShowLockScreen();
 ? ? ? ?let xhr = cc.loader.getXMLHttpRequest();
 ? ? ? ?xhr.onreadystatechange = function () {
 ? ? ? ? ? ?// cc.log('xhr.readyState=' + xhr.readyState + ' ?xhr.status=' + xhr.status);
 ? ? ? ? ? ?if (xhr.readyState === 4 && xhr.status == 200) {
 ? ? ? ? ? ? ? ?let respone = xhr.responseText;
 ? ? ? ? ? ? ? ?let rsp = JSON.parse(respone);
 ? ? ? ? ? ? ? ?cc.myGame.gameUi.onHideLockScreen();
 ? ? ? ? ? ? ? ?callback(rsp);
 ? ? ? ? ? ?} else {
 ? ? ? ? ? ? ? ?callback(-1);
 ? ? ? ? ? ?}
 ? ? ? ?};
 ? ? ? ?xhr.open('POST', url, true);
 ? ? ? ?// if (cc.sys.isNative) {
 ? ? ? ?xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
 ? ? ? ?xhr.setRequestHeader('Access-Control-Allow-Methods', 'GET, POST');
 ? ? ? ?xhr.setRequestHeader('Access-Control-Allow-Headers', 'x-requested-with,content-type');
 ? ? ? ?xhr.setRequestHeader("Content-Type", "application/json");
 ? ? ? ?xhr.setRequestHeader('Authorization', 'Bearer ' + cc.myGame.gameManager.getToken());
 ? ? ? ?// }

 ? ? ? ?// note: In Internet Explorer, the timeout property may be set only after calling the open()
 ? ? ? ?// method and before calling the send() method.
 ? ? ? ?xhr.timeout = 8000;// 8 seconds for timeout

 ? ? ? ?xhr.send(JSON.stringify(params));
 ? ?},

 ? ?/**
 ? ? * 登錄專用
 ? ? * @param {string} url 
 ? ? * @param {object} params 
 ? ? * @param {function} callback 
 ? ? * @param {string} account 
 ? ? * @param {string} password 
 ? ? */
 ? ?httpPostLogin(url, params, callback, account, password) {
 ? ? ? ?cc.myGame.gameUi.onShowLockScreen();
 ? ? ? ?let xhr = cc.loader.getXMLHttpRequest();
 ? ? ? ?xhr.onreadystatechange = function () {
 ? ? ? ? ? ?// cc.log('xhr.readyState=' + xhr.readyState + ' ?xhr.status=' + xhr.status);
 ? ? ? ? ? ?if (xhr.readyState === 4 && xhr.status == 200) {
 ? ? ? ? ? ? ? ?let respone = xhr.responseText;
 ? ? ? ? ? ? ? ?let rsp = JSON.parse(respone);
 ? ? ? ? ? ? ? ?cc.myGame.gameUi.onHideLockScreen();
 ? ? ? ? ? ? ? ?callback(rsp);
 ? ? ? ? ? ?} else {
 ? ? ? ? ? ? ? ?callback(-1);
 ? ? ? ? ? ?}
 ? ? ? ?};
 ? ? ? ?xhr.open('POST', url, true);
 ? ? ? ?xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
 ? ? ? ?xhr.setRequestHeader('Access-Control-Allow-Methods', 'GET, POST');
 ? ? ? ?xhr.setRequestHeader('Access-Control-Allow-Headers', 'x-requested-with,content-type');
 ? ? ? ?xhr.setRequestHeader("Content-Type", "application/json");
 ? ? ? ?let str = account + "@" + password;
 ? ? ? ?xhr.setRequestHeader('Authorization', 'Basic' + ' ' + window.btoa(str));

 ? ? ? ?xhr.timeout = 8000;// 8 seconds for timeout

 ? ? ? ?xhr.send(JSON.stringify(params));

 ? ?}
});

window.HttpHelper = new HttpHelper();


Cocos Creator JS http通信封裝的評論 (共 條)

分享到微博請遵守國家法律
白山市| 永春县| 蓬安县| 拉孜县| 阿合奇县| 延吉市| 阿拉善盟| 遂平县| 呼图壁县| 扎鲁特旗| 马尔康县| 宁阳县| 布尔津县| 墨脱县| 旬阳县| 周至县| 西青区| 枞阳县| 晋中市| 唐海县| 馆陶县| 肃北| 古交市| 齐河县| 乌海市| 沁水县| 汝阳县| 岱山县| 临西县| 房产| 南宁市| 来安县| 抚宁县| 双牌县| 玉山县| 台北市| 新龙县| 辽宁省| 鹤峰县| 蓝田县| 汽车|