...

trouble getting ajax to show data

mhunt
04-04-2007, 09:33 PM
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";
}
}
?>

snake_eyes
04-04-2007, 09:38 PM
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

mhunt
04-04-2007, 09:41 PM
nope still didnt work

snake_eyes
04-04-2007, 09:48 PM
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);
}

mhunt
04-04-2007, 09:54 PM
Thanks that works, you are awesome

snake_eyes
04-04-2007, 10:04 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum