javascript ajax #js

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript ajax #js相关的知识,希望对你有一定的参考价值。

/**post**/
var request = new XMLHttpRequest();
request.open('POST', '/my/url', true);
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
request.send(data);


/**request**/
var request = new XMLHttpRequest();
request.open('GET', '/my/url', true);

request.onload = function() {
  if (request.status >= 200 && request.status < 400) {
    // Success!
    var resp = request.responseText;
  } else {
    // We reached our target server, but it returned an error
    if (request.status == 400) {
              alert('There was an error 400');
           }
           else {
               alert('something else other than 200 was returned');
           }

  }
};

request.onerror = function() {
  // There was a connection error of some sort
};
request.timeout = 10000
request.ontimeout = function(){
    
}
request.onprogress = function(e){
    if(e.lengthComputable){
        e.position
        e.totalSize
    }
}
request.send();

以上是关于javascript ajax #js的主要内容,如果未能解决你的问题,请参考以下文章

javascript Ajax JS

javascript 停ajax.js

javascript AJAX与Vanilla JS

javascript ajax #js

javascript ajax state #js

javascript ajax #js