dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: What is the problem in this code?

  1. #1
    Join Date
    Jul 2009
    Posts
    1

    What is the problem in this code?

    The ajax script does not do anything when I press one of the links. How can I fix this problem?
    The actual page: http://www.roastedgarlic.ws/calendar/bar.php
    bar.php
    Code:
    <html><head>
    <script language="javascript" type="text/javascript" src="internal_request.js"></script>
    </head>
    <body>
    <?php
      echo '<h1>Latest Events</h1>';
      echo '<ul>';
      $query = "SELECT * FROM events WHERE date >= NOW() ORDER BY date, starttime";
      $result = mysqli_query($dbc, $query);
      $numrows = mysqli_num_rows($result);
      
      if($numrows == 0) {
        echo 'No events!';
      }
      else {
        while($row = mysqli_fetch_array($result)) {
          echo '<li><a href="#" onclick="getEvent(' . $row['id'] . ')">' . $row['name'] . '</a> (<i>' . $row['date'] . '</i>)</li>';
        }
      }
      echo '</ul>';
    internal_request.js
    Code:
    function createReqestObject(){
      var request_o;
      var browser = navigator.appName;
      if(browser == "Microsoft Internet Explorer") {
        request_o = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      else{
        request_o = new XMLHttpRequest();
      }
      return request_o;
    }
    
    var http = createRequestObject();
    
    function getEvent(eventid){
      http.open('get', 'internal_request.php?action=getevent&id=' + eventid);
      http.onreadystatechange = handleEvent;
      http.send(null);
    }
    
    function handleEvent(){
      if(http.readyState == 4){
        var response = http.responseText;
        document.getElementById('eventcage').innerHTML = response;
      }
    }
    internal_request.php
    Code:
    <?php
      session_start();
      require('config.php');
    
      if($_GET['action'] == 'getevent') {
        $query = "SELECT * FROM events WHERE id = '" . $_GET['id'] . "'";
        $result = mysqli_query($dbc, $query);
        $row = mysqli_fetch_array($result);
      
        echo '<h1>Event Details</h1>';
        echo $row['name'];
        echo '<p>' . $row['description'] . '</p>';
        echo '<p><strong>Date:</strong> ' . date('D jS F Y', strtotime($row['date'])) . '<br>';
        echo '<strong>Time:</strong> ' . $row['starttime'] . ' - ' . $row['endtime'] . '</[';
      }
    ?>
    As I understand it, when I click on one of the links inside the bar, I am supposed to be able to view the details in the event cage, but when I click it, nothing happens.

  2. #2
    Join Date
    Mar 2007
    Location
    Bangalore, India
    Posts
    247
    In bar.php, where is $dbc defined? I think it is undefined and causing problem.

Similar Threads

  1. Control Arrays in VB.NET
    By Gary Nelson in forum .NET
    Replies: 277
    Last Post: 10-01-2003, 12:00 AM
  2. wot is CLR
    By lostguy in forum .NET
    Replies: 8
    Last Post: 04-03-2002, 07:41 PM
  3. Brain Washing
    By Danny Bowman in forum .NET
    Replies: 152
    Last Post: 09-13-2001, 07:23 AM
  4. Problem with asp code
    By Guillermo in forum ASP.NET
    Replies: 0
    Last Post: 08-01-2001, 10:03 AM
  5. Replies: 0
    Last Post: 04-03-2001, 04:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center