zoukankan      html  css  js  c++  java
  • JavaScript Ajax 取消请求防重处理(完美解决LBS轮询重复刷新问题)

    Ajax 原生XHR方式:

    var native = new XMLHttpRequest();
    native.open("GET","https://api.github.com/");
    native.send();
    native.onreadystatechange=function(){
        if(native.readyState==4&&native.status==200){
            console.log(native.response);           
        }else{
            console.log(native.status);
        }
    }
    native.abort();
    

      

    Jquery方式:

    var requestAjax= $.ajax({
        type:"get",
        url:"https://api.github.com/",
        dataType:"json",
        success:function(data){
            console.log(data);
        },
        error:function(err){
            console.log(err);
        }
    })
    requestAjax.abort();
    

      

    注意:一般有LBS地图应用的系统定时器可以用Aajx请求控制反复重新请求问题(地图缩放平移事件)。

  • 相关阅读:
    Js变量类型
    前端面试题HTML
    AP聚类
    锚点
    html
    Active Learning主动学习
    z-index
    position
    学习笔记_卷积神经网络
    学习笔记_深度学习的数学基础
  • 原文地址:https://www.cnblogs.com/boonya/p/13615259.html
Copyright © 2011-2022 走看看