My index.php
switch ($action){
case "calendar":
echo "<script language=\"javascript\">\n";
echo "document.write('Hello World!')";
echo "</script>";
include($_STR_TEMPLATEPATH."/calendar_view.php");
break;
}
my calendar_view.php:
I have an ajax function which should call the action calendar from the index and display the result on calendar_view.php in calendar div
<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>
The calendar div:
<div id="calendar"></div>
When I call the calendarList function it did call the case, but did not display the result in calendar div.
Any help. Thanks
-
You're doing it wrong. Please see stackoverflow.com/questions/11658596/…Dmitry Pashkevich– Dmitry Pashkevich2012年08月13日 08:33:06 +00:00Commented Aug 13, 2012 at 8:33
2 Answers 2
There is not much to display there. If everything works like you described, the response is appended to the DOM, but the JavaScript-alert will never be executed.
Try alert(xmlHttp.responseText); to be absolutely sure that your response is correct. If it is, you can go from there.
4 Comments
alert(xmlHttp.responseText);.Instead of using a script to write thee text just output text
switch ($action){
case "calendar":
echo "Hello World!";
include($_STR_TEMPLATEPATH."/calendar_view.php");
break;
}
I don't think inserting scripts with innerHTML works see Can scripts be inserted with innerHTML?