ajax異步加載

點擊異步切換圖片,也稱異步加載數據,這就是ajax的奇特之處。
git

寫了一個很簡單的demo放到git了:http://koringz.github.io/ajax/github

js:
ajax

function  xmlhttp(argument) {異步

if(typeof ajax == 'undefined'){ide

try{this

ajax = new XMLHttpRequest();url

}spa

catch(e){orm

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

}

}

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 = 'p_w_picpaths/gyy' + this.index + '.jpg';

getcontent (value);

}

}

}

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

相關文章
相關標籤/搜索