本文介绍了javascript中的xmlhttpRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了以下代码
I have written following code
<script type="text/javascript" language="javascript">
function GetHttpRequestObject() {
xmlhttp = new XMLHttpRequest();
if (xmlhttp != null) {
xmlhttp.open("Get", "../Book.xml", true)
alert(xmlhttp.responseText);
}
else {
alert("not created");
}
}
</script>
我在根目录下有Book.xml文件.
当我运行此代码时,我收到空白警报消息,但是我认为它应该显示以xml编写的值.请在这里帮我
i have Book.xml file at root .
when i am running this code i am getting blank alert message, but i think it should show values written in xml. please help me out here
推荐答案
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
message1.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "../Book.xml", true);
xmlhttp.send();
试试吧...
Try it...
这篇关于javascript中的xmlhttpRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!