下面的方法是用JQUERY的方法写的.如果换为JAVASCRIPT的方法,怎么写?
JAVASCRIPT代码如下:
var divShrink= document.querySelector("div.shrink"), divAjax= document.querySelector("div.ajax"); divShrink.onclick= function(){ $.get(targeturl,function(data){ $(divAjax).html(data); }) }
HTML部分代码如下:
<div class="shrink"> </div> <div class="ajax" targeturl="./pr-NeteaseMusic.html"> </div>
数据分析师2017-10-01 00:49:50
用JavaScript怎麼取得AJAX的值?-PHP中文網問答-用JavaScript怎麼取得AJAX的值?-PHP中文網問答
圍觀一下哦,學習一下。
迷茫2017-03-13 09:20:57
function myAjax(type,url,param,callback){ var httpRequest; if(window.XMLHttpRequest){ httpRequest=new XMLHttpRequest(); }else{ httpRequest=new ActiveXObject("Microsoft.XMLHTTP"); } if(type=="get"){ httpRequest.open(type,url+"?"+param); httpRequest.send(null); }else if(type=="post"){ httpRequest.open(type,url); httpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); httpRequest.send(param); } httpRequest.onreadystatechange = callback; return httpRequest; }
var httpRequest = window.myAjax("get",url,"name=1",function(){ if(httpRequest.readyState==4&&httpRequest.status==200){ console.log(httpRequest.responseText) } }