javascript代碼我的index.php用PHP編寫
switch ($action){
case "calendar":
echo "<script language=\"javascript\">\n";
echo "document.write('Hello World!')";
echo "</script>";
include($_STR_TEMPLATEPATH."/calendar_view.php");
break;
}
我calendar_view.php:
我有一個AJAX功能,應該調用從index
的action
calendar
和calendar div
上calendar_view.php
顯示結果
<script>
function calendarList()
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
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 && xmlHttp.status==200)
{
document.getElementById("calendar").innerHTML=xmlHttp.responseText;
}
}
xmlHttp.open("GET","?action=calendar",true);
xmlHttp.send(null);
}
</scritp>
日曆格:
<div id="calendar"></div>
當我打電話給calendarList function
它確實調用了這種情況,但沒有在calendar div
中顯示結果。
任何幫助。由於
你做錯了。請參閱http://stackoverflow.com/questions/11658596/is-echoing-javascript-code-condtionally-based-on-server-side-logic-considered-ha/11658717 – 2012-08-13 08:33:06