Răsfoiți Sursa

update post func

zy_1995 7 luni în urmă
părinte
comite
b6576c88ad
1 a modificat fișierele cu 8 adăugiri și 10 ștergeri
  1. 8 10
      assets/Script/CustomClass/WebDataCenter.js

+ 8 - 10
assets/Script/CustomClass/WebDataCenter.js

@@ -105,24 +105,22 @@ WebDataCenter = cc.Class({
         xhr.send();
     },
 
-    httpPOST(url, param = {}, callback) {
-        // url = HttpUtil.baseUrl + url;
-        this.m_LinkCount++;
-        var xhr = cc.loader.getXMLHttpRequest();
+    httpPOST(url, data, callback) {
         let dataStr = '';
-        Object.keys(param).forEach(key => {
-            dataStr += key + '=' + encodeURIComponent(param[key]) + '&';
+        Object.keys(data).forEach(key => {
+            dataStr += key + '=' + encodeURIComponent(data[key]) + '&';
         })
         if (dataStr !== '') {
             dataStr = dataStr.substring(0, dataStr.lastIndexOf('&'));
         }
+
+        var xhr = cc.loader.getXMLHttpRequest();
         xhr.open("POST", url, true);
-        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+        xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
         xhr.onreadystatechange = function () {
-            if (xhr.readyState === 4 && (xhr.status >= 200 && xhr.status < 400)) {
-                this.m_LinkCount--;
+            if (xhr.readyState === 4 && (xhr.status >= 200 && xhr.status < 300)) {
                 let response = xhr.responseText;
-                callback(false, response);
+                callback(JSON.parse(response));
             }
         };
         xhr.send(dataStr);