2011-07-07 28 views
0

这里是一个HTML页面,我想用ajax加载一个带有php脚本的元素。加载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> 

加载的元素为空。它只有<html></html>。 ajax代码中的错误是什么造成的?

+0

什么是您的日历/ index.php脚本返回? –

+0

@Marc B,index.php应该返回一个表格,每列包含一个div。如果我创建'src calendar/index.php?cP = 2',这将起作用。我想用ajax加载文件,而不是在创建表时加载页面的其他部分。 – user823527

回答

1

也许你需要确保状态是200分配src属性响应文本