Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-04-2007, 09:33 PM   PM User | #1
mhunt
Regular Coder

 
Join Date: Mar 2005
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
mhunt is an unknown quantity at this point
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:
Code:
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 Code:
<?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";
    }
}
?>
__________________
http://www.mh-interactive.com
mhunt is offline   Reply With Quote
Old 04-04-2007, 09:38 PM   PM User | #2
snake_eyes
New Coder

 
Join Date: Mar 2007
Posts: 74
Thanks: 0
Thanked 0 Times in 0 Posts
snake_eyes is an unknown quantity at this point
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
snake_eyes is offline   Reply With Quote
Old 04-04-2007, 09:41 PM   PM User | #3
mhunt
Regular Coder

 
Join Date: Mar 2005
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
mhunt is an unknown quantity at this point
nope still didnt work
__________________
http://www.mh-interactive.com
mhunt is offline   Reply With Quote
Old 04-04-2007, 09:48 PM   PM User | #4
snake_eyes
New Coder

 
Join Date: Mar 2007
Posts: 74
Thanks: 0
Thanked 0 Times in 0 Posts
snake_eyes is an unknown quantity at this point
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....

your code should:

Code:
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);
}

Last edited by snake_eyes; 04-04-2007 at 09:50 PM.. Reason: UPDATE
snake_eyes is offline   Reply With Quote
Old 04-04-2007, 09:54 PM   PM User | #5
mhunt
Regular Coder

 
Join Date: Mar 2005
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
mhunt is an unknown quantity at this point
Thanks that works, you are awesome
__________________
http://www.mh-interactive.com
mhunt is offline   Reply With Quote
Old 04-04-2007, 10:04 PM   PM User | #6
snake_eyes
New Coder

 
Join Date: Mar 2007
Posts: 74
Thanks: 0
Thanked 0 Times in 0 Posts
snake_eyes is an unknown quantity at this point
Smile

thanks...

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

Code:
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

Last edited by snake_eyes; 04-04-2007 at 10:09 PM.. Reason: adding information
snake_eyes is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:17 PM.


Advertisement
Log in to turn off these ads.