加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ajax异步加载

发布时间:2020-12-16 01:50:44 所属栏目:百科 来源:网络整理
导读:点击异步切换图片,也称异步加载数据,这就是ajax的奇特之处。 写了一个很简单的demo放到git了:http://koringz.github.io/ajax/ js: function xmlhttp(argument) { if(typeof ajax == 'undefined'){ try{ ajax = new XMLHttpRequest(); } catch(e){ ajax =

点击异步切换图片,也称异步加载数据,这就是ajax的奇特之处。

写了一个很简单的demo放到git了:http://koringz.github.io/ajax/

js:

function xmlhttp(argument) {

if(typeof ajax == 'undefined'){

try{

ajax = new XMLHttpRequest();

}

catch(e){

ajax = new ActiveXObject('Microsoft.XMLHTTP');

}

}

return ajax;

}


function getcontent (url) {

var request = xmlhttp();


request.open('get',url,true);

request.onreadystatechange = function () {

if(request.readyState == 4){

var img = '<img src="'+ url +'" />';

console.log('typeof eval(img)');

document.querySelector('.box-inline-block').innerHTML = img;

}

}

request.send(null);

}


window. function(){

var input = gettag('input');

console.log(input + '2');

for(var i = 0; i<input.length;i++){

console.log(input[i]);

input[i].index = i;

input[i].onclick = function () {

var value = 'images/gyy' + this.index + '.jpg';

getcontent (value);

}

}

}

下载地址:https://github.com/koringz/ajax

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读