我正在 php 和 jquery 项目中工作,我使用 ajax 向服务器端发出请求
现在我的 php 文件的 ajax 响应有问题
我有以下 php 代码
<?php
require 'db.php';
$code = $_POST['code'];
$status = 0;
$count = 0;
$name = "";
$guarantors = 0;
$sql = "SELECT * FROM clients WHERE code='$code'";
$result = mysqli_query($link, $sql);
if(mysqli_num_rows($result) > 0){
$row = mysqli_fetch_array($result);
$name = $row['name'];
$status = 1;
$sqli = "SELECT * FROM guarantors WHERE client_code='$code'";
$resulti = mysqli_query($link, $sqli);
if(mysqli_num_rows($resulti) > 0){
$guarantors = '[';
while($rowi = mysqli_fetch_array($resulti)){
$count ++;
$guarantors .= '{id:'.$rowi['id'].', name:'.$rowi['guarantor_name'].'},';
}
$guarantors .= ']';
}else{
$guarantors = "0";
}
}else{
$status = 0;
$returnText = "إسم المستخدم تم إستخدامه من قبل !";
}
echo json_encode(array("status"=>$status,"name"=>$name,"guarantors"=>$guarantors));
?>
我有这个 jquery 代码
$.ajax({
url:"read_client.php",
method:"POST",
data: {code:$('.code').val()},
dataType: 'json',
success:function(response){
if(response.status == 1){
var result = $.parseJSON(response);
console.log(result.guarantors.name)
YAFloader.close()
}else{
Swal.fire(
'error'
)
YAFloader.close()
}
}
});
现在我想获取每个id和namefrom guarantors,但我做不到
我需要帮助,请快点,有人可以帮助我吗???
谢谢你们
陪伴而非守候