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

upon data retrieval, form populates and then clears

本文关键字:填充 然后 清除 表单 检索 数据      更新时间:2023-09-26

我有一个奇怪的问题。我有一个表单,其中填充了一个按钮单击事件。这一切都很好,只是一旦表单填充,它就会自行清除。甚至萤火虫也被清除了。我已经把一切都剥离到最基本的层面,不知道问题是什么。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中进行硬编码,而不是每次都要键入它,但无论哪种方式,结果都是一样的。关于如何解决这个问题有什么想法吗??

试试这个:

$(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
});
相关文章: