ajax 不錯的應用
<script type="text/javascript" language="javascript">
var http_request = false;
function makeRequest(url) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
http_request.onreadystatechange = alertContents;
http_request.open('GET', url, true);
http_request.send(null);
}
function alertContents() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
alert(http_request.responseText);
} else {
alert('There was a problem with the request.');
}
}
}
</script>
<span
style="cursor: pointer; text-decoration: underline"
onclick="makeRequest('test.html')">
Make a request
</span>
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁面才能執(zhí)行]
相關(guān)文章
Ajax 給 XMLHttpReq.onreadystatechange傳遞參數(shù)
這篇文章主要介紹了Ajax如何給XMLHttpReq.onreadystatechange =函數(shù)傳遞參數(shù),需要的朋友可以參考下2014-05-05
django中使用jquery ajax post數(shù)據(jù)出現(xiàn)403錯誤的解決辦法(兩種方法)
在django中,使用jquery ajax post數(shù)據(jù),會出現(xiàn)403的錯誤,大家知道該如何解決嗎?下面由腳本之家小編給大家分享兩種解決辦法,需要的朋友可以參考下2015-09-09
jQuery通過Ajax向PHP服務端發(fā)送請求并返回JSON數(shù)據(jù)
這篇文章主要介紹了jQuery通過Ajax向PHP服務端發(fā)送請求并返回JSON數(shù)據(jù),設(shè)計到的知識點有jquery、ajax、php、json,感興趣的朋友一起學習下jquery ajax 返回json2015-10-10
php+ajax實現(xiàn)帶進度條的大數(shù)據(jù)排隊導出思路以及源碼
最近在做一個項目,我們現(xiàn)在有很多數(shù)據(jù),分表存放,項目要求在導出的時候需要有進度條。經(jīng)過一番思索,完成了一下內(nèi)容,分享給大家。最后面有完整代碼。2014-05-05

