web前端|js教程
javascript,ajax,实现
web前端-js教程上一篇文章写到原生js取代jquery的一些常用函数:原生js仿jquery一些常用方法,那么,ajax如何实现呢?如下是一个比较完整的ajax()
仿qq聊天软件源码,ubuntu挂载sd,tomcat9安装服务,爬虫下载ppt,php开源网盘系统源码,360seo优化开户费用lzw
function ajax(){ var ajaxData = {type:arguments[0].type || "GET",url:arguments[0].url || "",async:arguments[0].async || "true",data:arguments[0].data || null,dataType:arguments[0].dataType || "text",contentType:arguments[0].contentType || "application/x-www-form-urlencoded",beforeSend:arguments[0].beforeSend || function(){},success:arguments[0].success || function(){},error:arguments[0].error || function(){} } ajaxData.beforeSend() var xhr = createxmlHttpRequest(); xhr.responseType=ajaxData.dataType; xhr.open(ajaxData.type,ajaxData.url,ajaxData.async); xhr.setRequestHeader("Content-Type",ajaxData.contentType); xhr.send(convertData(ajaxData.data)); xhr.onreadystatechange = function() {if (xhr.readyState == 4) { if(xhr.status == 200){ ajaxData.success(xhr.response) }else{ ajaxData.error() }} } } function createxmlHttpRequest() { if (window.ActiveXObject) {return new ActiveXObject("Microsoft.XMLHTTP"); } else if (window.XMLHttpRequest) {return new XMLHttpRequest(); } } function convertData(data){ if( typeof data === object ){var convertResult = "" ;for(var c in data){ convertResult+= c + "=" + data[c] + "&";}convertResult=convertResult.substring(0,convertResult.length-1)return convertResult; }else{return data; } }
使用格式跟jquery的ajax差不多:
驱动级dll注入源码,vscode 提示错误,java上传文件到ubuntu,tomcat 使用ssl,sqlite查询所有列名,人人照片插件,流行的前端框架vue,怎么绕开爬虫协议,bt下载php,深圳seo教程网,手机pc 网站系统,易语言自动浏览网页,简单网页模板源码下载,页面滚动代码,超市采购管理系统,dt b2b程序lzw
ajax({ type:"POST", url:"ajax.php", dataType:"json", data:{"val1":"abc","val2":123,"val3":"456"}, beforeSend:function(){//some js code }, success:function(msg){console.log(msg) }, error:function(){console.log("error") } })
网站源码交易网源码,ubuntu粘贴复制卡,付费小说爬虫吗,php红色号,惠安seo渠道lzw