通过AJAX返回的JavaScript无法正常工作。如何使用JavaScript的工作吗? [英] JavaScript returned by AJAX is not working. How to work with JavaScript?

查看:143
本文介绍了通过AJAX返回的JavaScript无法正常工作。如何使用JavaScript的工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

喜 这是我的网页Test1.asp

hi this is my page 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

This is requested page 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是不工作

In the page (Test2.asp) javascript is not working

我要如何使用AJAX调用test2.asp我test1.asp

How do i call test2.asp to my test1.asp using ajax

推荐答案

在默认情况下包含的JavaScript与AJAX响应。

By default JavaScript contained with AJAX responses is not executed.

有一个在从头开始建立一个Ajax处理程序时,这个问题已经在各个库就像jQuery和原型解决了没有意义的。

There is no point in building an Ajax handler from scratch when this problem has already be solved in various libraries just as jQuery and Prototype.

这篇关于通过AJAX返回的JavaScript无法正常工作。如何使用JavaScript的工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆