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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jul 2012
    Location
    Canada :)
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Is it just not doing what you are expecting? Or does it display a message in the error console?
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #3
    New to the CF scene
    Join Date
    Jul 2012
    Location
    Canada :)
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    there is no output when onclick, database not updated too.

  • #4
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    One thing that I noticed from your code is that the <td>'s are not being closed, nor do I see any content. The AJaX appears correct, to me; at least I don't immediately see anything incorrect. If the database isn't updating, it's most likely in the PHP processing page "adminupdate.php".
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #5
    New to the CF scene
    Join Date
    Jul 2012
    Location
    Canada :)
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i found the problem, my function change() did not have a close "}"


  •  

    Posting Permissions

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