到我的ajax响应中,我得到了这个值:
orderDetail: Array(1)
0:
area_name: "Barisal Sadar"
city_name: "Barisal"
email: "namixypi@mailinator.com"
fname: "Ivana"
id: 6
lname: "Rocha"
message: null
pay_type: "Bkash"
phone: "017845698532"
pick_up_date: "2021-09-21"
pick_up_time: null
required_services: "1,2,3"
[[Prototype]]: Object
length: 1
[[Prototype]]: Array(0)
我有三个复选框,当我插入required_services值到数据库我发送它作为一个字符串。现在我需要获取数据并按名称显示它们。1代表熨烫,2代表干洗,3代表洗涤。我正在使用Ajax。如何使用Ajax按名称显示它们
My Ajax Code:
$(document).on('click', '#viewOrder', function(e) {
e.preventDefault();
let orderId = $(this).val();
// alert(orderId);
$.ajax({
type: "GET",
url: "/getOrder/" + orderId,
success: function(response) {
console.log(response);
$('#orderTablemodal tbody').html('');
$.each(response.orderDetail, function(key, item) {
$('#orderTablemodal tbody').append(
'<tr>
<td><b>Customer Phone No.</b></td>
<td>'+item.phone+'</td>
</tr>
<tr>
<td><b>Customer Name: </b> </td>
<td>' + item.fname +' '+item.lname+'</td>
</tr>
<tr>
<td><b>E-mail: </b> </td>
<td>' + item.email +'</td>
</tr>
<tr>
<td><b>Location: </b></td>
<td>'+item.area_name+', '+item.city_name+'</td>
</tr>
<tr>
<td><b>Services :</b> </td>
<td>Iron*** Here I need to show my services name ****</td>
</tr>
<tr>
<td><b>Pay type: </b> </td>
<td>' + item.pay_type +'</td>
</tr>');
});
}
});
});
如果我理解对了你的问题,请使用split:
let string = "1,2,3";
console.log(string.split(","));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>