在数据检索时,表格填充然后清除

时间:2014-09-15 12:33:46

标签: javascript php jquery ajax

我有一个奇怪的问题。我有一个填充按钮单击事件的表单。这一切都很好,除了一旦表格填充,它就会自行清除。甚至Firebug也被清除了。我把所有东西都剥离到最基本的水平,并且无法弄清楚问题是什么。 HTML:

<?php

require_once('../hyperlink.php');
?>

<!DOCTYPE html>
<html>
<head>
<title>Shipment Assignment</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<link rel="stylesheet" href="book.css">
<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="../css/styles.css" />
<link rel="stylesheet" href="../css/tabletheme/style.css" type="text/css" id="" media="print, projection, screen" />
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/themes/smoothness/jquery-ui.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/jquery-ui.js"></script>
<script type="text/javascript" src="../barcode/jquery-barcode.js"></script>
<script type="text/javascript" src="../js/tablesorter.min.js"></script>
<script src="book.js"></script>
</head>
<body>
<div id="header">

<?php display_user_hyperlinks(); ?>

<?php include ('../version.php'); ?>  | Tip: Shipping Info</p>

</div>
<form>
    <fieldset>
        <legend>Shipping Assignments</legend>
Enter the PO that you would like to review: <input id="po"/><input type="submit" id="getPo" value="Retrieve"/>
</fieldset></form>
<form id="result">
<div id="hide">
    <div id="cl" class="width border">
        CL<input id="cl"/>
    </div>
    <div id="recv" class="width border">
        REC<input id="rec"/>
    </div>
    <div id="pricePd" class="width border">
        <input id="price" placeholder="Price Paid"/>
    </div>
    <div id="box" class="border">
        <input id="title" style="width: 445px;" placeholder="Title"/><br>
        <input id="isbn10" style="width: 445px;" placeholder="ISBN10"/><br>
        <input id="isbn13" style="width: 445px;" placeholder="ISBN13"/><br>
    </div>
</div></form>
    <div id="remain"class="border">
    Qty Rem: <input type="text"  id="qtyRem"/>
</div>

</body>
</html>

book.js

$(document).ready(function() {
$("#getPo").click(function() {

    $.ajax ({
        type: "POST",
        url: "poInfo.php",
        async:false,
        dataType: "json",
        data: ({po: $('#po').val()}),
        success: function(data){
            console.log(data);

            $("#isbn13").val(data.isbn);
            $("#isbn10").val(data.isbn10);
            $("#title").val(data.title);

       }
   }); //END OF AJAX
 }); // END OF GETPO FUNCTION

});

poInfo.php:

<?php
ini_set('display_errors',"1");
require_once ('../db.php');
$conn = db_connect();
$i=0;
$po = 'JJD090969';

$result = $conn->query("select * from ship_assign where po = '$po'");
while ($row = $result->fetch_assoc()) {
$isbn10 = $row['isbn10'];
$isbn = $row['isbn13'];
$azLow = $row['azLow'];
$buyback101 = $row['Buyback101'];
$textRecycle = $row['textBookRecycle'];
$textRush = $row['textBookRush'];
$bookStores = $row['bookStores'];
$textBooks = $row['textBooks'];
$bookJingle = $row['bookJingle'];
$cash4Books = $row['cash4Books'];
$bookbyte = $row['bookbyte'];
$sellBack = $row['sellBack'];
$cheggBs = $row['chegg'];
$valore = $row['valore'];
$powell = $row['powell'];
$amzBuyBack = $row['amazonBuyBack'];
$collegeBooksDir = $row['collegeBooksDirect'];

$result2 = $conn->query("select title from book where isbn13 = '$isbn'");
$row1 = $result2->fetch_assoc();
$title = $row1['title'];
} //END OF WHILE STATEMENT
$guides= array('isbn10'=>$isbn10,'isbn'=>$isbn,'title'=>$title);

$conn->close();
echo json_encode($guides);
?>

一切都按预期工作,除了表格填充后清除。我很难在po中编写我想要使用的代码,而不是每次都要输入它,但结果是相同的。关于如何解决这个问题的任何想法??

1 个答案:

答案 0 :(得分:0)

试试这个:

$(document).ready(function() {
$("#getPo").click(function(event) {
event.preventDefault();
    $.ajax ({
        type: "POST",
        url: "poInfo.php",
       // async:false, deprecated
        dataType: "json",
        data: ({po: $('#po').val()}),
        success: function(data){
            console.log(data);

            $("#isbn13").val(data.isbn);
            $("#isbn10").val(data.isbn10);
            $("#title").val(data.title);

       }
   }); //END OF AJAX
 }); // END OF GETPO FUNCTION

});