SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jul 2012
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    AJAX not working

    Hello people, I'm currently working on a website, building a booking system.

    So...somehow my AJAX is not working and got me question mark =(

    Below is the code.

    In homepage.php:

    <script type='text/javascript'>

    function change(ro,cc)
    {
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("GET","adminupdate.php?q="+ro+"&w="+cc, true);
    xmlhttp.send(null);
    </script>

    .
    .
    .
    .
    <tr>
    <td>Table1</td>
    <?php
    $slotresult = mysql_query("select * from checkslot WHERE row='1' AND checkcol='1'"); //select all field from logintable and put into result
    if(!$slotresult)
    {
    die("Database connection fail: " . mysql_error());
    }
    $row2 = mysql_fetch_array($slotresult);
    if ($row2[status]==0)
    {
    ?>
    <td id="table11000" onclick="change(1,1)" style="background-color:greenyellow">
    <?php

    }
    if ($row2[status]==1)
    {
    ?>
    <td id="table11000" onclick="change(1,1)" style="background-color:red">
    <?php

    }
    if ($row2[status]==2)
    {
    ?>
    <td id="table11000" onclick="change(1,1)" style="background-color:blue">
    <?php

    }

    ?>
    .
    .
    .

    In adminupdate.php:

    <?php
    $connection = mysql_connect("localhost","root","123456") or die(mysql_error());
    mysql_select_db('bookingdb',$connection);

    $row=$_GET["q"];
    $col=$_GET["w"];
    $slotresult = mysql_query("UPDATE checkslot SET status='1' WHERE checkcol LIKE ('".$row."') AND row LIKE ('".$col."') ");
    if(!$slotresult)
    {
    die("Database connection fail: " . mysql_error());
    }
    mysql_query($slotresult) or die(mysql_error());


    ?>

    yeah, not sure where the error is, hope you guys can try your best to understand my program thanks for reading.

    -->There is no output when onclick and database not updated.

    Edit/Delete Message

  2. #2
    Non-Member
    Join Date
    Jul 2012
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First thing that needs to be checked is the url to the php script.

    Do an

    Code:
    alert("adminupdate.php?q="+ro+"&w="+cc);
    and make sure the output is corrrect. When it is, then start going through the php script code.

    To debug the php code, you can echo any outputs and they will appear in ajax object's responseText property.

    Btw, it might be a good idea to also have an onreadystatechange event handler to check if the ajax request actually completes or not.


Bookmarks

Posting Permissions

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