提交按钮不适用于Ajax加载PHP页面

时间:2011-06-30 16:00:04

标签: php ajax forms submit

我的页面加载键入,显示必要的信息,但提交按钮不起作用。我尝试将标签放在外面,但它始终选择表格底部的用户ID。

以下是搜索页面的代码:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Checkout</title>


<script type="text/javascript">

function showHint(str)
{
if (str.length==0)
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","ajax-search.php?keyword="+str,true);
xmlhttp.send();
}
</script>

</head>

<body>


<?php

        include('./stuff.php');

        $ai = sanitize($_POST['golfcart_id']);
        session_start();
        $_SESSION['cartId'] = $ai;


        $a = new A();
        #queries golfcart_info for name based off of the golfcart id
        $golfcart_table = $a->querySelect("*","golfcart.golfcart_info","golfcart_id = '$ai'");
        $row=mysql_fetch_array($golfcart_table);
?>

            <h1>Checkout </h1>

            <table>

            <tr>
            <td>golfcart id</td><td> <?php echo $ai; ?></td>
            </tr>

            <tr>
            <td>golfcart name</td><td> <?php echo $ai; ?></td>
            </tr>

            <tr>
            <td height='20px'></td>
            </tr>

            <tr>
            <td><label for='user_username'>Username:  </label></td>
            <td><input  name="user" size=30 type="text" id="faq_search_input" onkeyup='showHint(this.value)' /></td>
            </tr>

            </table>



        <span id="txtHint"></span>
        <input type='button' value='Go Back' onClick='history.go(-1)'/>  
</body>

</html>

这是加载的页面:

<?php
# Including our DB Connection file
include_once ('db_conn.php');


if(isset($_GET['keyword']))
{
    session_start();
    # IF the url contains the parameter "keyword"
    $keyword = trim($_GET['keyword']) ;//Remove any extra  space
    $keyword = mysqli_real_escape_string($dbc, $keyword);//Some validation

    $query = "select * from golfcart_users where user_username like '%$keyword%'";
    # The SQL Query that will search for the word typed by the user .

    $result = mysqli_query($dbc,$query);//Run the Query

    if($result)
    {
        # If query successfull
         if(mysqli_affected_rows($dbc)!= 0)
         {
            # and if atleast one record is found
            echo "<table border='0'><br>";
            echo "<th width='153px' style='border: 1px solid grey;'>Sign In</th>";
            echo "<th width='153px' style='border: 1px solid grey;'>Username</th>";
            echo "<th width='153px' style='border: 1px solid grey;'>First Name</th>";
            echo "<th width='153px' style='border: 1px solid grey;'>Last Name</th>";
            echo "<th width='153px' style='border: 1px solid grey;'>Department</th>";
            echo "<th width='153px' style='border: 1px solid grey;'>Contact Info</th>";
            while($row = mysqli_fetch_array($result,MYSQLI_ASSOC))
            {
                ?>
                <form action='./script_checkout.php' method='post'>
                <input type='submit' value='<?php echo $_SESSION['cartId']; ?> '/>
                <tr align='center'>
                <td style='border: 1px solid grey;'>
                <input type='hidden' name='user_id' value='<?php echo $row['user_id']; ?>'/>
                <input type='hidden' name='username' value='<?php echo $row['user_username']; ?>'/>
                <input type="radio" name='select' value='<?php echo $row['user_username']; ?>' />
                </td>
                <td style='border: 1px solid grey;'><?php echo $row['user_username']; ?></td>
                <td style='border: 1px solid grey;'><?php echo $row['user_fname']; ?></td>
                <td style='border: 1px solid grey;'><?php echo $row['user_lname']; ?></td>
                <td style='border: 1px solid grey;'><?php echo $row['user_department']; ?></td>
                <td style='border: 1px solid grey;'><?php echo $row['user_contact']; ?></td>
                </tr>
                </form>

            <?php   
            } // end while loop 

            echo "</table>";
         } // end if mysql affected rows
         else 
         {
             echo 'No Results for :"'.$_GET['keyword'].'" Click <a href=./createuser.php>Here</a> to input a Username for Golfcart checkout.';//No Match found in the Database
         } // end else

    } //end if $result

} // end if isset keyword

else 
{
    echo 'Parameter Missing in the URL';//If URL is invalid
} // end if else

?>

非常感谢!

0 个答案:

没有答案