gpt4 book ai didi

javascript - ajax data.success 代码块未被执行(变量值)

转载 作者:行者123 更新时间:2023-11-29 10:55:27 26 4
gpt4 key购买 nike

我在 regrading ajax 请求时遇到了很大的问题。如果 ajax 请求成功,我想将变量值设置为 1,如果不成功,它保持为 0。但是我的程序无法正常工作。问题是什么以及如何解决问题?

$(document).on('click', '.overtime_send', function() {
temp = 0;
$('#employee_table tbody tr').each(function(row, tr) {

var emp_no = $(tr).find('td:eq(0)').text();
var ot_hours = $(tr).find('input').val();

//ot_array.push([emp_no,ot_hours]);

$.ajax({
url: 'otrequset_action.php',
type: 'POST',
data: { action:'add_ot',emp_no : emp_no, ot_hours:ot_hours},
dataType:"json",
success:function(data)
{
if(data.success)
{
swal("Good job!", "OverTime Request Send Successfully!", "success");
temp = 1;
dataTable.ajax.reload();
}
}
});
});
alert(temp);//data.success alert display but value is still 0
if (temp == 1) {
$.ajax({
url: 'otrequset_action.php',
type: 'POST',
data: { action:'add_comment'},
dataType:"json",
success:function(data)
{
if(data.success)
{
dataTable.ajax.reload();
}
}
});
}
swal({title: "No data entering?",text: "Not set the overtime hours !",type: "warning"});

});

最佳答案

(document).on('click', '.overtime_send', function() {
temp = 0;
$('#employee_table tbody tr').each(function(row, tr) {

var emp_no = $(tr).find('td:eq(0)').text();
var ot_hours = $(tr).find('input').val();

//ot_array.push([emp_no,ot_hours]);

$.ajax({
url: 'otrequset_action.php',
type: 'POST',
data: { action:'add_ot',emp_no : emp_no, ot_hours:ot_hours},
dataType:"json",
success:function(data)
{
swal("Good job!", "OverTime Request Send Successfully!", "success");
temp++;
dataTable.ajax.reload();
if (temp == 1) {
$.ajax({
url: 'otrequset_action.php',
type: 'POST',
data: { action:'add_comment'},
dataType:"json",
success:function(data)
{
if(data.success)
{
dataTable.ajax.reload();
}
}
});
}
}
});
});

swal({title: "No data entering?",text: "Not set the overtime hours !",type: "warning"});

});

关于javascript - ajax data.success 代码块未被执行(变量值),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58443528/

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