繁体   English   中英

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

[英]upon data retrieval, form populates and then clears

我有一个奇怪的问题。 我有一个用按钮单击事件填充的表单。 一切工作正常,除了一旦填充表格,它就会清除自身。 甚至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中进行硬编码,而不必每次都键入,但是两种方法的结果都是相同的。 有想法该怎么解决这个吗??

尝试这个:

$(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

});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM