警报框显示错误发生的时间

时间:2018-05-22 08:24:47

标签: javascript c# jquery asp.net bootstrap-modal

我正在寻找实现引导警报框,因为我在页面上有并发错误。目前,这是控制器的设置方式:

2 个答案:

答案 0 :(得分:2)

我会用sweetalert2做这样的事情:

https://jsfiddle.net/x07g89h9/

bootstrap

https://jsfiddle.net/mmq27s86/2/

<强> HTML

声明bootstrap模态

<div id="myModal" class="modal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Errors</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
         <ul id="errors">

         </ul>
      </div>
      <div class="modal-footer">
        <button type="button" data-dismiss="modal" class="btn btn-primary">Close</button>
      </div>
    </div>
  </div>
</div>

<强> JS

  function showModal(errors){
        var $msg = $("#errors");
        $msg.empty();
        for(var i=0; i<result.errors.length; i++){
             $msg.append("<li>" + errors[i] + "</li>");
        }
        $('#myModal').modal();
   }

   $.ajax({
            url: 'any...',
            data: JSON.stringify(model),
            type: 'POST',
            cache: false,
            contentType: 'application/json',
            success: function (result) {



                // in case of error
                if(result.ChangeStatus !== "Success"){

                     showModal(result.errors);
                }
            },
            error: function () { 
                $('#errorContainer').show(); 
                $('#errorMessage').html('There was a server error, please contact the support desk on (+44) 0207 099 5991.'); 
            }
        });
    });

答案 1 :(得分:0)

检查thisthis

文章太长,无法在此报告整个代码。