用JavaScript怎么获取AJAX的值?
烟雨江南
烟雨江南 2017-03-13 09:20:09
0
2
896

下面的方法是用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>
烟雨江南
烟雨江南

reply all(2)
数据分析师

How to get the value of AJAX using JavaScript?-PHP Chinese website Q&A-How to get the value of AJAX using JavaScript?-PHP Chinese website Q&A

Look around and learn.

迷茫
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)
        }
    }
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template