使用ajax加载的元素为空

发布于 2024-11-19 02:46:57 字数 2103 浏览 2 评论 0原文

这是一个 HTML 页面,我想使用 ajax 加载带有 php 脚本的元素。

<?php require_once('connect.php'); ?>

<!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=iso-8859-1" />

<?php require("pagetitle.php"); ?>

<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame Remove this if you use the .htaccess -->
<!-- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> -->

<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.3/themes/base/jquery-ui.css" type="text/css" media="all" 

/>

<!-- Portal JavaScript -->
<script type="text/javascript" src="portal.js"></script>

<script type="text/javascript">
    var http = false;
    if(navigator.appName == "Microsoft Internet Explorer") {
      http = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
      http = new XMLHttpRequest();
    }
    function LoadCalendar() {
      http.abort();
      http.open("GET", "calendar/index.php?cP=2", true);
      http.onreadystatechange=function() {
        if(http.readyState == 4) {
          document.getElementById('litcal').src = http.responseText;
        }
      }
      http.send(null);
    }
</script>

</head>

<body onload="appendTitle('Calendar');">

<div id="content-body"><a name="top"></a>
  <h1>
    <iframe id="litcal" onload="LoadCalendar();" style="padding: 0px 0px 0px 0px; border: 1px solid #404040;" width="690px" 
height="691px"></iframe>
  </h1>  
</div> <!-- End CONTENT-BODY div -->

</body>
</html>

加载的元素为空。它只有 。 ajax代码中的什么错误导致了这个?

Here is an HTML page where I want to load an element with a php script using ajax.

<?php require_once('connect.php'); ?>

<!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=iso-8859-1" />

<?php require("pagetitle.php"); ?>

<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame Remove this if you use the .htaccess -->
<!-- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> -->

<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.3/themes/base/jquery-ui.css" type="text/css" media="all" 

/>

<!-- Portal JavaScript -->
<script type="text/javascript" src="portal.js"></script>

<script type="text/javascript">
    var http = false;
    if(navigator.appName == "Microsoft Internet Explorer") {
      http = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
      http = new XMLHttpRequest();
    }
    function LoadCalendar() {
      http.abort();
      http.open("GET", "calendar/index.php?cP=2", true);
      http.onreadystatechange=function() {
        if(http.readyState == 4) {
          document.getElementById('litcal').src = http.responseText;
        }
      }
      http.send(null);
    }
</script>

</head>

<body onload="appendTitle('Calendar');">

<div id="content-body"><a name="top"></a>
  <h1>
    <iframe id="litcal" onload="LoadCalendar();" style="padding: 0px 0px 0px 0px; border: 1px solid #404040;" width="690px" 
height="691px"></iframe>
  </h1>  
</div> <!-- End CONTENT-BODY div -->

</body>
</html>

The loaded element is empty. It only has <html></html>. What error in the ajax code caused this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

压抑⊿情绪 2024-11-26 02:46:57

也许您需要在将 src 属性分配给响应文本之前确保状态为 200

maybe you need to make sure the status is 200 before assigning the src attribute to the response text

梦幻的味道 2024-11-26 02:46:57

问题是 PHP 没有返回 URL。所以ajax无法给src分配任何东西。请参阅此问题以获取有效的代码。

https://stackoverflow.com/questions /6612918/loading-an-iframe-with-ajax/6618656#6618656

The problem was that the PHP was not returning a URL. So ajax could not assign anything to the src. See this question for the code that worked.

https://stackoverflow.com/questions/6612918/loading-an-iframe-with-ajax/6618656#6618656

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文