dtg25862 2014-09-15 12:33
浏览 45
已采纳

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

I have a weird problem. I have a form that populates with a button click event. This all works fine, except that once the form populates, it clears itself. Even Firebug gets cleared. I have stripped everything down to its most basic level, and cannot figure out what the issue is. 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);
?>

Everything works as it should, except that the form clears once populated. I am hard coding in the po that I want to use instead of having to type it in every time, but the result is the same either way. Any ideas on how to fix this??

  • 写回答

1条回答 默认 最新

  • dp198879 2014-09-15 12:40
    关注

    Try this:

    $(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
    
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度