【问题标题】:Calling ajax function from ajax从ajax调用ajax函数
【发布时间】:2015-09-10 08:16:46
【问题描述】:

单击按钮并调用插入时调用以下代码 _all 函数,它是一个 ajax 函数。成功我发出警报但没有工作 json 调用liquidations_a_insert_all.jsp 工作正常。

$(document).ready(function() {
 $('#click1').click(function(event) {
     var auditorid = $('input:hidden[id=Wauditorid]').val();
     $.ajax({
         type: 'GET',
         url: 'groupauditors.jsp',
         data: {
             Woauditorid: auditorid
         },
         dataType: 'json',
         success: function(data) {
             $.each(data, function(index, element) {
                    var currRow = $("#tr0").clone().appendTo($('#items')).attr('id','tr' + (index + 1));
                    currRow.find('td:eq(0)').html(index + 1);
                    currRow.find('.subgroupid').html(element.subgroupid);
                    currRow.find('.auditorid').html(element.auditorid);

                    insert_all(element.auditorid, "", "");
             });
         }
        });
    });
});

调用 insert_all(element.auditorid, "", "");

function insert_all(auditorid, onSuccess, onFail) {
 $.ajax({
         type: 'GET',
         url: 'liquidations_a_insert_all.jsp',
         data: {
             Wauditorid: auditorid
         },
         dataType: 'json',
         success: function(data) {
                    alert("insert_all");
//$( 'table tbody tr td:last-child').html(data.inserted);
                    }
     });
 }

有什么想法吗?

【问题讨论】:

  • 可能返回的数据不是json类型的你检查了吗?
  • 你确定insert_all真的被调用了吗?
  • Pekka 你说得对,我的 jsp 标签破坏了 json 类型。
  • 请接受我的回答

标签: javascript jquery json ajax jsp


【解决方案1】:

我希望在两个 ajax 函数中都使用async:false,

$(document).ready(function() {
 $('#click1').click(function(event) {
     var auditorid = $('input:hidden[id=Wauditorid]').val();
     $.ajax({
         type: 'GET',
         url: 'groupauditors.jsp',
         data: {
             Woauditorid: auditorid
         },
         async:false,
         dataType: 'json',
         success: function(data) {
             $.each(data, function(index, element) {
                    var currRow = $("#tr0").clone().appendTo($('#items')).attr('id','tr' + (index + 1));
                    currRow.find('td:eq(0)').html(index + 1);
                    currRow.find('.subgroupid').html(element.subgroupid);
                    currRow.find('.auditorid').html(element.auditorid);

                    insert_all(element.auditorid, "", "");
             });
         }
        });
    });
});


function insert_all(auditorid, onSuccess, onFail) {
 $.ajax({
         type: 'GET',
         url: 'liquidations_a_insert_all.jsp',
         data: {
             Wauditorid: auditorid
         },
         async:false,
         dataType: 'json',
         success: function(data) {
                    alert("insert_all");
//$( 'table tbody tr td:last-child').html(data.inserted);
                    }
     });
 }

【讨论】:

    猜你喜欢
    • 2021-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-17
    相关资源
    最近更新 更多