gpt4 book ai didi

javascript - 如果数据库中存在数据则显示警报图标 - JQuery AJAX

转载 作者:行者123 更新时间:2023-12-03 03:45:26 25 4
gpt4 key购买 nike

我有一个表,我需要在其中检查数据是否已存在于数据库中。如果这样做,则相应行的“操作”列下的垃圾桶图标旁边应出现一个警报图标,并显示有关它们的适当信息。

目前,如果我要比较的数据已经存在于数据库中,我就能够返回我需要的ajax数据。但我不知道如何在各自的行上显示图标。

enter image description here

这是我返回的数据:

{"receive_array":[{"id":"77","batch_id":"45","courier_name":"","vendor_name":"","status":"stored","batch_no":"9","courier_tracking_no":"123"},"",{"id":"126","batch_id":"65","courier_name":"QW12","vendor_name":"Amazon","status":"itemized","batch_no":"18","courier_tracking_no":"QW11"}]}

这是我的 Ajax:

$.ajax({
type: "POST",
url: window.base_url+'oss/admin/check_receive_data',
data: $.param($('form#receiving-form').serializeArray()),
dataType : 'JSON',
success: function (response) {
//THIS IS WHERE THE PROCESS SHOULD TAKE PLACE
$.each(response.receive_array, function(index, val) {
});
},
error: function (MLHttpRequest, textStatus, errorThrown) {
console.log("There was an error: " + errorThrown);
}
});

编辑:

HTML:

<table id="receiving-box-table" class="table table-hover table-bordered table-striped">
<thead>
<tr>
<th>Courier Tracking #</th>
<th>Courier</th>
<th>Vendor</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" form="receiving-form" class="form-control input-sm track_no" name="courier_tracking_no[]" id="courier_tracking_no_1" /></td>
<td><input type="text" form="receiving-form" class="form-control input-sm" name="courier_name[]" id="courier_name_1" onkeypress="if (event.keyCode == 13) {return false;}"/></td>
<td><input type="text" form="receiving-form" class="form-control input-sm" name="vendor_name[]" id="vendor_name_1" onkeypress="if (event.keyCode == 13) {return false;}"/></td>
<td class="box-action"><button class="btn btn-danger btn-xs clear-data" data-toggle="tooltip" data-placement="right" title="Clear input fields"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button></td>
</tr>
</tbody>
</table>

(除了第一行之外的行是动态创建的。)

非常感谢任何帮助。谢谢!-伊莱

最佳答案

您需要 2 个循环 1 来匹配数据,其他是您从数据库获得的响应,例如,

....
success: function (response) {
// Change selectors as per you HTML design
$('table tr').each(function(index){
var ctno=$(this).find('td:first input').val(); // get courier trancking

// check if ctno is present in response array or not
var arr = jQuery.grep(response.receive_array, function( n ) {
return ( n.courier_tracking_no === ctno);
});
if(arr.length){ // if present then show error message
$('span.exists').show(); // let it be hidden by default
}
});

},
....

关于javascript - 如果数据库中存在数据则显示警报图标 - JQuery AJAX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45412275/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com