The AJAX is working but with a slight problem it refreshes the page after it runs map.php and all the output from map.php disappears from the screen back to the original state before map.php is called!????
map.php
Code:
<script type="text/javascript" language="javascript">
var loading_img = '../../images/layout/loading.gif';
var loading_msg = ' Loading Data...';
var xmlhttp_obj = false;//create the XMLHttpRequest
function ewd_xmlhttp()
{
if (window.XMLHttpRequest)
{ // if Mozilla, Safari etc
xmlhttp_obj = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{ // if IE
try
{
xmlhttp_obj = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlhttp_obj = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
}
}
}
else
{
xmlhttp_obj = false;
}
return xmlhttp_obj;
} //get content via GET
function getcontent(url, containerid)
{
var xmlhttp_obj = ewd_xmlhttp();
document.getElementById(containerid).innerHTML = '<img src="' + loading_img + '" />' + loading_msg;
xmlhttp_obj.onreadystatechange=function()
{
loadpage(xmlhttp_obj, containerid);
}
xmlhttp_obj.open('GET', url, true);
xmlhttp_obj.send(null);
alert(url);
}
function loadpage(xmlhttp_obj, containerid)
{
if ( xmlhttp_obj.readyState == 4 && xmlhttp_obj.status == 200 )
{
document.getElementById(containerid).innerHTML = xmlhttp_obj.responseText;
}
}
//]]>
</script>
...
<input type="text" id="date" name="date" size="10" onfocus="showCalendarControl(this);" readonly="readonly" />
<input type="submit" value="Refresh" onclick="getcontent('../../map.php?id=1&value='+document.getElementById('date').value,'case_map_wrapper');" />
Code:
<?php
session_start();
$txt = "";
$id = $_GET['id'] != "" ? preg_replace("#[^0-9]#","",$_GET['id']) : "1";//I use preg_replace to sanitze the get request
$value = $_GET['value'];
if($value != '') {
if($id == 1) {
echo '<div id="case_map_wrapper">'.$value.'</div>';
}
}
else {
echo '<div id="case_map_wrapper">all</div>';
}
?>
Comment