gpt4 book ai didi

javascript - 发生错误时显示的警报框

转载 作者:行者123 更新时间:2023-12-01 02:02:10 25 4
gpt4 key购买 nike

我希望实现引导警报框,以便当页面上出现并发错误时。目前 Controller 的设置方式如下:

最佳答案

我会用 sweetalert2 做这样的事情:

https://jsfiddle.net/x07g89h9/

或者使用引导

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

HTML

声明引导模式

<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.');
}
});
});

关于javascript - 发生错误时显示的警报框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50463073/

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