首页 > Web开发 > 详细

ajax异步加载

时间:2015-10-11 19:55:06      阅读:345      评论:0      收藏:0      [点我收藏+]

点击异步切换图片,也称异步加载数据,这就是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


本文出自 “this is share blog” 博客,请务必保留此出处http://kosig.blog.51cto.com/9218084/1701723

ajax异步加载

原文:http://kosig.blog.51cto.com/9218084/1701723

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!