http.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { _decorator, Component, Node } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('http')
  4. export class http {
  5. static login(){
  6. var xml = new XMLHttpRequest()
  7. xml.open('POST',"http://120.79.128.142:9502/api/v1/login")
  8. xml.setRequestHeader('Content-Type','text/plain');
  9. xml.send("{“token”:””,”wx_openid”:””,”wx_name”:””,”wx_avatar”:””,”ios_openid”:””,”account”:”13412598083”,”verify_code”:”1234”}")
  10. var array:String[] = ['loadstart','abort', 'error', 'load', 'loadend', 'timeout'];
  11. array.forEach(function (eventName) {
  12. xml[('on' + eventName) as 'onloadstart' | 'onabort' | 'onerror' | 'onload' | 'onloadend' | 'ontimeout'] = function () {
  13. var str = '\nEvent : ' + eventName;
  14. var lstr = ""
  15. if (eventName === 'timeout') {
  16. lstr += '(timeout)';
  17. }
  18. else if (eventName === 'loadend') {
  19. lstr += '...loadend!';
  20. }
  21. console.log("str==",str)
  22. console.log("lstr==",lstr)
  23. };
  24. });
  25. // Special event
  26. xml.onreadystatechange = function () {
  27. if (xml.readyState === 4 && xml.status >= 200) {
  28. //label.string = handler(xml.responseText);
  29. console.log("xml.responseText==",xml.responseText)
  30. } else if (xml.status === 404) {
  31. console.log("status ==",'404 page not found!')
  32. } else if (xml.readyState === 3) {
  33. console.log("status ==",'Request dealing!')
  34. } else if (xml.readyState === 2) {
  35. console.log("status ==", 'Request received!')
  36. } else if (xml.readyState === 1) {
  37. console.log("status ==", 'Server connection established! Request hasn\'t been received')
  38. } else if (xml.readyState === 0) {
  39. console.log("status ==", 'Request hasn\'t been initiated!')
  40. }
  41. };
  42. }
  43. }