【发布时间】:2018-02-18 16:02:57
【问题描述】:
脚本
$('#c1').change(function() {
var serial = $(this).val();
$.ajax({
type : "GET",
dataType: 'html',
url : "getserial.php",
data : {id:serial},
success :function(data) {
var result = $.parseJSON(data);
$('#c4').val(result.curr_serial);
}
})
})
HTML
<select name="c1" id="c1">
<option value="">Select a type:</option>
<option value="JC">JC - Jackets</option>
<option value="PN">PN - Polo Neck</option>
<option value="RN">RN - Round Neck</option>
</select>
<input type="text" class="form-control" name="c4" id="c4" maxlength="3">
PHP 用于从数据库中获取序列号。
require 'include/dbh.php';
$serial = $_REQUEST['c1'];
$sql = "Select `curr_serial` from serial where product='$serial'";
$result = mysqli_query($con,$sql);
$row = mysqli_fetch_array($result);
json_encode($row);
我得到的错误是:
Uncaught SyntaxError: Unexpected end of JSON input at Function.parse [as parseJSON] (<anonymous>) at Object.success (addproduct.php:383)
我无法理解我在哪里犯了错误。
【问题讨论】:
-
在您的 PHP 脚本中执行
return json_encode($row);。 -
您好,欢迎来到 StackOverflow。请花一些时间阅读帮助页面,尤其是名为"What topics can I ask about here?" 和"What types of questions should I avoid asking?" 的部分。更重要的是,请阅读the Stack Overflow question checklist。您可能还想了解Minimal, Complete, and Verifiable Examples。
标签: javascript php html mysql ajax