我必须从数据库中拥有两个不同的查询检索到的2个表,需要在JSON进行编码并发送至ajax.The问题是我不能够通过2个JSON的阿贾克斯。 我与回波json_encode(阵列($ DATA1,DATA2 $))尝试;但它不起作用。json_encode超过2个阵列
//我的PHP代码
$query = $db->query("select * from table1 where valu1='".$value1."'");
while ($row = $query->fetch_assoc()) {
$data1['value1'] = $row['value1'];
$data1['value2'] = $row['value2'];
}
$query = $db->query("select * from table2 where value2='".$value2."' ");
while ($row = $query->fetch_assoc()) {
$data2['value2'] = $row['value2'];
$data2['value3'] = $row['value3'];
}
echo json_encode(array($data1,$data2));
//我的AJAX代码
$(document).ready(function(){
$('#Form').submit(function(e){
e.preventDefault(); // stops the form submission
$.ajax({
url:$(this).attr('action'), // action attribute of form to send the values
type:$(this).attr('method'), // method used in the form
data:$(this).serialize(), // data to be sent to php
dataType:"json",
success:function(data){
//main
alert(data.value1);
},
error:function(err){
alert(err);
}
});
});
});
在提前解决这个issue.Thanks请帮助
[SQL注射是衰](http://stackoverflow.com/documentation/php/5828/pdo/2685/preventing-sql-注射与参数化查询#t = 201705031212354359734),采取[这与你!](http://php.net/manual/en/mysqli.prepare.php) – JustCarty
嘿,首先要确保,$ data1和$ data2不是空的。其次,你应该检查通过开发工具的输出响应,以确保如果输出是一个JSON对象 –