duanquan1243 2011-07-07 17:04
浏览 70
已采纳

用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?

  • 写回答

2条回答 默认 最新

  • doushi1900 2011-07-08 01:08
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记