gpt4 book ai didi

javascript - 将 Ajax 错误响应显示为网页

转载 作者:行者123 更新时间:2023-12-03 05:53:25 26 4
gpt4 key购买 nike

来自如下构建的 Ajax 调用:

 function GetData() {
$.ajax({
type: "POST",
url: "@Model.RouteForAjaxLastValue",//"/RCharts/AjaxMethod",//
data: "{Id: " + lastID+ "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {

},
failure: function (response) {
alert(response.responseText);
},
error: function (response) {
alert(response.responseText);
}
})

我有时会收到这样的回复:

Error-Message as Alert

我可以看到,这是一个网页,因为它是整个页面的 html 格式。

但是有没有办法直接将其显示为新页面呢?

在我还没来得及读到错误可能是什么之前,它就切断了警报中的其余消息......

最佳答案

在成功函数中使用 $("html").html(response.responseText);

success : function(response){
$("html").html(response.responseText);
}

关于javascript - 将 Ajax 错误响应显示为网页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40048467/

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