兼容IE AJAX封装 全步骤

您所在的位置:网站首页 ajax兼容ie 兼容IE AJAX封装 全步骤

兼容IE AJAX封装 全步骤

2024-07-10 17:08| 来源: 网络整理| 查看: 265

Ajax封装六步骤

1.有浏览器 支持 没有浏览器请求发送不出去 2.创建Ajax对象 3.Ajax.open(method,url,true0); 设置请求 4.ajax.send(); 发送数据 5.onreadystatechage 监听数据返回事件 6.status 数据状态

详情看代码`

function ajaxFun(method,url,data,callback,flag){ //传请求方式 url 数据 回调函数 同步false/异步true var xhr = null; if(window.XMLHttpRequest){ xhr = new.XMLHttpRequest(); //创建Ajax对象 }else{ xhr = new.ActiveXObject('Microsoft.XMLHttp'); //兼容ie } if(method = 'GET'){ //兼容‘GET’ 和‘post’ xhr.open(method,url + '?' + data,flag) ; // ( 数据传输方式 ,url地址 ,异步true/同步false) GET请求参数拼接在url后面 xhr.send(); //把数据发送 }else if(method = 'POST'){ xhr.oprn(method,url,flag); xhr.setRequestHeader('Content-type','application/x-www-form-urlencoded&


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3