我已经尝试了很多方法,从发布的教程和其他问题,但似乎没有任何效果。我正在尝试使用 jquery 将数据从 php 发送到 div 和变量中。我在 php 端设置了数组,一切正常,但在 jquery 端我总是得到一个意外的标识符错误或 div 留空或两者兼而有之
var var_numdatacheck = <?php echo $datacheck; ?>;
var var_rowtest = parseInt(var_numdatacheck);
function waitupdate(){
$.ajax({
type: 'POST',
url: 'update.php',
data: {function: '3test', datacheck: var_rowtest},
dataType: "json",
success: function(check) {
var data = JSON.parse(check);
var_rowtest = data[id]; // sets the variable numcheck as the new id number
$('#datacheck').html(data[0]); // I've confirmed data[0] has a value but the div is left blank
}
error: function(msg) {
console.log(msg)// here i get an unexpected identifier error
}
});
}
$(document).ready(function() {
waitupdate();
});
php的输出是
{"id":"4","0":"Name"}
这是实际的php代码
<?php
require "dbc.php";
$function = $_POST['function'];
$datacheck = $_POST['datacheck'];
$search="SELECT * FROM Feedtest ORDER BY id DESC";
$request = mysql_query($search);
$update= mysql_fetch_array($request);
$updateid = $update['id'];
$updatecheck = mysql_num_rows($request);
$data = array();
if ($function == $datacheck){
echo $updatecheck;
echo $datacheck;
}
if ($function == "3test" && $updatecheck > $datacheck ) {
$updatesearch="SELECT * FROM Feedtest WHERE id = '$updateid' ORDER BY id DESC";
$updatequery = mysql_query($updatesearch);
$check['id'] = $updateid;
while ($row = mysql_fetch_array($updatequery)){
?>
<?php $check[]= $row['First Name']; ?>
<?php
}
echo json_encode($check);
}
?>
</div>
</ul>