如何使用jquery比较两个数字?
var delivered_qty = [];
var deli_qtydbvalue =[];
var delivered_qty = 1,2,3
var deli_qtydbvalue =1,4,3
$('.delivered_qty').each(function() {
delivered_qty.push($(this).val());
deli_qtydbvalue.push($(this).attr('orginaldbvalue'));
});
此处第二列不匹配,如果不匹配,则在此处调用ajax。如果不等于,则仅调用ajax?
我尝试循环
for(var i = delivered_qty.length; i--;) {
if(delivered_qty[i] !== deli_qtydbvalue[i]){
$.get("updatedeliverystatus.php", {
delivered_qty: delivered_qty,
invoiceitemsID: invoiceitemsID,
delivered_status: delivered_status,
getinvoiceno: getinvoiceno
}).done(function(data) {
if (data == "1") {
$.alert({
title: 'Message',
type: 'green',
typeAnimated: true,
content: 'Delivery Quantity is updated successfully',
draggable: true,
})
}
});
}//end if
}//end for loop
答案 0 :(得分:0)
此查询将为您提供解决方案
for(var i = delivered_qty.length; i--;) {
if(delivered_qty[i] !== deli_qtydbvalue[i]){
/* calling ajax with async false */
$.ajax({
url : "updatedeliverystatus.php",
type : "get",
data: {
delivered_qty: delivered_qty,
invoiceitemsID: invoiceitemsID,
delivered_status: delivered_status,
getinvoiceno: getinvoiceno
}
async: false,
success : function(data) {
//nothing to do here
}
});
/*check if its the last loop. Move it outside the loop for better code readability*/
if(i == delivered_qty.length -1) {
$.alert({
title: 'Message',
type: 'green',
typeAnimated: true,
content: 'Delivery Quantity is updated successfully',
draggable: true,
});
}
}//end if
}//end for loop