87,910
社区成员
发帖
与我相关
我的任务
分享
if(xhr.status == 200 || xhr.status == 0) {
document.getElementById('divTip').innerHTML = xhr.responseText;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="scripts/jquery-1.4.4.min.js"></script>
<style type="text/css">
body { margin:0; padding:0; }
.divFrame { border:1px solid #000; width:150px; }
#buttons { border:1px solid #000; }
.divContent { padding:5px; }
.divTitle { padding:3px; background:#CCC; }
</style>
</head>
<body>
<div class="divFrame">
<div class="divTitle">
<input type="button" id="buttons" value="提交" />
</div>
<div class="divContent">
<div id="divTip"></div>
</div>
</div>
<script type="text/javascript">
function createXHR() {
var xhr = null;
if(window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
return xhr;
} else if(window.ActiveXObject) {
xhr = new ActiveXObject('Microsoft.XMLHTTP');
return xhr;
} else {
alert('初始化XMLHTTP错误');
}
}
function getSendData() {
//document.getElementById('divTip').innerHTML = '<img src="Loading.gif" title="正在加载中......" />';
var xhr = createXHR();
url = 'untitled.html?data=' + Date();
xhr.open('GET', url, false);
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
if((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304) {
document.getElementById('divTip').innerHTML = xhr.responseText;
}
}
};
xhr.send(null);
}
document.getElementById('buttons').onclick = getSendData;
/*$('#buttons').click(function() {
$('#divTip').load('untitled.html');
});*/
</script>
</body>
</html>