关闭模式弹出窗口,然后显示另一个

时间:2020-06-11 07:58:07

标签: jquery ajax

我正在尝试关闭一个模式,然后在使用AJAX发生错误时打开另一个模式。但是,它似乎在error函数中不起作用。它在success函数中正常工作。

$('#modSending').modal({
  backdrop: 'static',
  keyboard: false
});

$.ajax({
  url: '/api/myapi/saverep?id=' + tid,
  dataType: 'json',
  type: 'POST',
  contentType: 'application/json; charset=utf-8',
  success: function(result) {
    //this part is working
    $('#modSending').modal('hide');
    $('#lblAlertHead').text("MySystem - Success");
    $('#pMessage').text("Request has been save.");
    $('#modAlert').modal({
      backdrop: 'static',
      keyboard: false
    });
    $('#btnAlertMsg').attr('onclick', "$('#modAlert').modal('hide')")
    $('#txtCategory').val('');
    cat_loadDetails(tg);
  },
  error: function(xhr) {
    var getxhr = $.parseJSON(xhr.responseText);

    //close modal modSending
    $('#modSending').modal('hide');
    $('#lblAlertHead').text("MySystem - Error");
    $('#pMessage').text(getxhr.Message);
    $('#btnAlertMsg').attr('onclick', "$('#modAlert').modal('hide')");

    //open modal modAlert
    $('#modAlert').modal({
      backdrop: 'static',
      keyboard: false
    });

    return;
  }
});

0 个答案:

没有答案