[英]Pass json array from php
我沒有花幾個小時來尋找解決問題的方法,卻找不到答案。
我正在同一頁面上進行搜索,為此,我正在使用Jquery,AJAX和PHP。
來自php的數組仍然返回undefined。
PHP代碼:
$i=0;
while($eee = mysqli_fetch_array($result)) {
$array[$i][1] = $eee['ex'];
$array[$i][2] = $eee['ex'];
$array[$i][3] = $eee['ex'];
$array[$i][4] = $eee['ex'];
$array[$i][5] = $eee['ex'];
$array[$i][6] = $eee['ex'];
$array[$i][7] = $eee['ex'];
$i = $i + 1;
}
json_encode($array)
AJAX和JQUERY
jQuery(document).ready(function(){
$(document).on('submit', '#FormData', function(e) {
$.ajax({
url: $(this).attr('action'),
type: $(this).attr('method'),
data: $(this).serialize(),
success: function(data) {
console.log(data[1]);
}
});
e.preventDefault();
});
});
感謝您的幫助;)
在您的php文件中使用echo json_encode($array);
在你的jQuery中
type: 'json',
method:'post'
,
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.