• 原生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);
    }
    }
    };
    }

    }
  • 相关阅读:
    C#微信开发文档
    XML相关操作
    css基本样式总结
    CSS选择器及其优先级
    Java学习之路(七)
    G2( bizCharts ) React 绘制混合图例
    G2 绘制混合图例 demo
    python 前后端分离 简单的数据库返回接口
    nginx 跨域
    react-router-dom
  • 原文地址:https://www.cnblogs.com/chaoyuehedy/p/5956793.html
Copyright © 2020-2023  润新知