Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Mar 2005
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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";
        }
    }
    ?>

  • #2
    New Coder
    Join Date
    Mar 2007
    Posts
    74
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #3
    Regular Coder
    Join Date
    Mar 2005
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts
    nope still didnt work

  • #4
    New Coder
    Join Date
    Mar 2007
    Posts
    74
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #5
    Regular Coder
    Join Date
    Mar 2005
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks that works, you are awesome

  • #6
    New Coder
    Join Date
    Mar 2007
    Posts
    74
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •