-2

此代码在数据库中找到一个 scu 并在您键入时显示它。它适用于除 Firefox 之外的所有浏览器(chrome、IE、opera)。如果有人能明白为什么我会非常感激帮助。

<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script>
<script src="chData_test.js"></script>

</head>
<body>
<form name="testForm">
<input type="text" name="scu" id="scu"><input type="button" id="theButton">
</form>
<div id="output"></div>
</body>

$(document).ready(function() {
  $('#theButton').click(get);
  $('#scu').keyup(get);
  function get() {
    $.post('data.php', {scu:testForm.scu.value}, function(output) {
      $('#output').text(output).show();
    });
  }
});

<?php
mysql_connect("***.000webhost.com", "a9414387_***", "****");
$scu = mysql_real_escape_string($_POST['scu']);

if ($scu==NULL) {
echo "No entry scu found";
}
else {
$description = mysql_query("SELECT description FROM a9414387_***.inventory WHERE id LIKE '$scu%'");
$description_num_rows = mysql_num_rows($description);
if ($description_num_rows==0) {
echo "scu not found in database";
}
else {
$description = mysql_result($description, 0);
echo "You have selected the $description";
}
}

?>
4

2 回答 2

1

使用 true 代替 "testForm.scu.value" -> "$('#scu').val()",例如:

function get() {
  var postdata = $('#scu').val();
    $.post('data.php', {scu:postdata}, function(output) {
      $('#output').text(output).show();
    });
  }
于 2012-06-01T18:11:42.107 回答
0

在引用它之前尝试定义“函数获取”。

$(document).ready(function() {
  function get() {
    $.post('data.php', {scu:testForm.scu.value}, function(output) {
      $('#output').text(output).show();
    });
  }
  $('#theButton').click(get);
  $('#scu').keyup(get);
});
于 2012-06-01T16:21:11.323 回答