问题描述
默认情况下,不执行AJAX响应中包含的JavaScript。
当已经像jQuery和Prototype一样在各种库中解决了此问题时,从头开始构建Ajax处理程序是没有意义的。
解决方法
这是我的页面Test1.asp
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
<script type="text/javascript">
function Alex()
{
var xmlHttp;
try
{
xmlHttp=new XMLHttpRequest(); }
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.getElementById("Alex").innerHTML =xmlHttp.responseText;//Get Google Destination Map
}
}
xmlHttp.open("GET","Test2.asp",true);
xmlHttp.send(null);
}
</script>
</head>
<body>
<div id ="Alex"></div>
<label onclick="Alex()" >ssss</label>
</body>
</html>
这是请求页面Test2.asp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>
<body>
<div id="Mathew"></div>
</body>
<script type="text/javascript" >
{
document.getElementById("Mathew").innerHTML='ajax is working';
}
</script>
</html>
在页面(Test2.asp)中,javascript无法正常工作
我如何使用Ajax将test2.asp调用到我的test1.asp