webmc

ajax交互模型:

    1.用户发出异步请求

    2.利用onReadyStateChange监听

    3.创建请求,用open方法指定是 get 还是 post,是否异步,url地址

    4.发送请求,send方法

    5.接受结果并分析

    6.实现刷新

同步异步区别:

  同步:脚本会停留并等待服务器发送回复然后再继续

  异步:脚本允许页面继续其进程并处理可能的回复

 

var xhr = new XMLHttpRequest();
xhr.open(\'请求方式GET或者POST或者其他\', 请求地址url, 是否开启异步async);
xhr.onreadystatechange = function() {
    // readyState == 4说明请求已完成
    if (xhr.readyState == 4 && xhr.status == 200) {
        console.log(xhr.responseText);
    }
}
if (method == \'POST\') {
    //给指定的HTTP请求头赋值
    xhr.setRequestHeader(\'Content-type\', \'application/x-www-form-urlencoded\');
}
xhr.send()

 

分类:

技术点:

相关文章:

  • 2021-12-27
  • 2021-12-20
  • 2021-12-20
  • 2021-11-14
  • 2021-10-19
猜你喜欢
  • 2021-12-27
  • 2021-11-14
  • 2021-10-19
  • 2022-01-01
  • 2021-10-19
  • 2021-10-19
相关资源
相似解决方案