Helpful Information
 
 
Category: Ajax and Design
trouble getting ajax to show data

ok so i have a calendar, and it shows a link under the day that has an event on it and when i click that date theres an onlick="getEvent('somedatehere')
but im not getting any response from the php file maybe someone can tell me what i am doing wrong.
javascript:


var xmlhttp = false;

try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch(E) {
xmlhttp = false;
}
}
if(!xmlhttp && typeof XMLHttpRequest != 'undefined') {
xmlhttp = new XMLHttpRequest();
}

function getEvent($date) {
//make the box visible
serverPage = "getEvent.php?date=$date";
var obj = document.getElementById("popup");
xmlhttp.open("GET", serverPage);
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
obj.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null);
}


php:


<?php
require_once('SystemComponent.php');
require_once('DbConnector.php');
require('make_safe.php');

$db = new DbConnector();

$date = make_safe($_GET['date']);
$result = $db->query("SELECT event_date, event_title, event_desc FROM calendar_events WHERE event_date = '$date'");
if(!$result) {
echo "failed";
} else {
while($row = $db->fetchArray($result)) {
echo $row['event_date']."<br />\n";
echo $row['event_title']."<br />\n";
echo $row['event_desc']."<br />\n";
}
}
?>

hello,

serverPage = "getEvent.php";

1- try to add true in the open, your code will be like: xmlhttp.open("GET", serverPage, true);

2- as I know much better to pass the variable in the send like: xmlhttp.send(date=$date);

cheers

nope still didnt work

dear, as I noticed in the javascript code there is Dollar sign
function getEvent($date) which is wrong try again with out $

if it still I'm working on your request.... please wait.... :D

your code should:



function getEvent(date)
{
//make the box visible
serverPage = "getEvent.php?date="+date;
var obj = document.getElementById("popup");

xmlhttp.open("GET", serverPage, true);
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
obj.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null);
}

Thanks that works, you are awesome

thanks...

this code should work also if god wills (not tested): :D



fillData("date", "date", "popup");

function fillData(GetParam, ParamData, ElById)
{
//-> GetParam assuming you want to use the same page but with different variable
var sPage = "getEvent.php?"+GetParam+"="+ escape(ParamData);

xmlhttp.open("GET", sPage, true);
xmlhttp.onreadystatechange = function() { getEvent(ElById); }
xmlhttp.send(null);
}

function getEvent(ElById)
{
if (xmlhttp.readyState == 4)
{
if (xmlhttp.status == 200)
{
var obj = document.getElementById(ElById);

obj.innerHTML = xmlhttp.responseText;
}
}
}


my god bless you
cordially










privacy (GDPR)