admin管理员组文章数量:1391964
I was reading w3schools tutorials for ajax and that url really bothered me. Where did they get that??I copied the sample code for ajax that w3schools have given but it doesnt work. I think its because of that url (demo_get.asp).. here is the code that i copied from w3schools.
<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc()
{
var xmlhttp;
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)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","demo_get.asp",true);
xmlhttp.send();
}
</script>
</head>
<body>
<h2>AJAX</h2>
<button type="button" onclick="loadXMLDoc()">Request data</button>
<div id="myDiv"></div>
</body>
</html>
I was reading w3schools tutorials for ajax and that url really bothered me. Where did they get that??I copied the sample code for ajax that w3schools have given but it doesnt work. I think its because of that url (demo_get.asp).. here is the code that i copied from w3schools.
<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc()
{
var xmlhttp;
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)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","demo_get.asp",true);
xmlhttp.send();
}
</script>
</head>
<body>
<h2>AJAX</h2>
<button type="button" onclick="loadXMLDoc()">Request data</button>
<div id="myDiv"></div>
</body>
</html>
Share
Improve this question
edited Jul 9, 2013 at 8:37
MrCode
64.6k10 gold badges92 silver badges113 bronze badges
asked Jul 9, 2013 at 8:33
jmjassy27jmjassy27
871 gold badge5 silver badges10 bronze badges
1 Answer
Reset to default 5demo_get.asp
is just the name of a file on the server that this AJAX example is reading. Just like any other url, you need to change it to match your code structure. For example, if you need to AJAX load html page mypage.html
, then that's what you need to put into the URL.
Also, unless you have good reason not too, you may be better off using a javascript library, for example, jQuery, which simplifies ajax a lot. In jQuery you can simply do:
$.get('mypage.html', function(data) {
$('#targetdiv').html(data);
});
to load the content of mypage.html
into the div
with id targetdiv
.
本文标签: javascriptWhat is this demogetaspStack Overflow
版权声明:本文标题:javascript - What is this demo_get.asp? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744746840a2622934.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论