zoukankan      html  css  js  c++  java
  • 原生ajax封装

    function ajax(method,url,data,dispatch){
    if (window.ActiveXObject){
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }else if (window.XMLHttpRequest){
    xmlHttp = new XMLHttpRequest();
    }
    xmlHttp.open(method,url,true);

    xmlHttp.setRequestHeader("Content-Type","application/json");
    //xmlHttp.setRequestHeader("charset","utf-8");
    xmlHttp.send(decodeURI(data));
    if(method.toLowerCase()=='get'){
    xmlHttp.onreadystatechange=callback;
    }else if(method.toLowerCase()=='post'){
    xmlHttp.onreadystatechange=function(){
    if (xmlHttp.readyState == 4) { //判断对象的状态是否交互完成
    if (xmlHttp.status == 200) { //判断http的交互是否成功,200表示成功
    console.log(xmlHttp.responseText);
    //回调传递参数
    let json = JSON.parse(xmlHttp.responseText);
    json.id = searchPlanObj.apId; //将点击那行的id传到reducers里对应的方法里
    if ( json["message"] == "success" ) {
    dispatch(receiveAssetPackInfo( json));
    }
    else {
    message.error(json['message']);
    }
    } else {
    alert('获取数据错误!错误代号:' + xhr.status + ',错误信息:' + xhr.statusText);
    }
    }
    };
    }

    }
  • 相关阅读:
    URLEncode解决url中有特殊字符的问题
    监控系统概览
    SpringBoot 上传文件夹
    关于postgresql报 ERROR: XXX does not exist
    postgresql学习
    git学习
    学习博客
    面试准备
    jvm
    线程池面试题
  • 原文地址:https://www.cnblogs.com/chaoyuehedy/p/5956793.html
Copyright © 2011-2022 走看看