gpt4 book ai didi

javascript - 在 jquery.form.js 中捕获状态代码

转载 作者:行者123 更新时间:2023-12-02 17:20:15 26 4
gpt4 key购买 nike

我正在尝试为我的应用程序制作一个表单调试器,并使用 jquery.form.js 提交表单。

但是我想捕获成功或错误的状态代码,我该怎么做?

我尝试了这个,但是 sta 变量只返回“成功”或“错误”,而不是我期望的状态代码,请帮忙。

$('form').ajaxSubmit({
success: function(res, sta, xhr, $form) {
$('#result-code').html(sta);
$('#result-content').html(res);
},
error: function(res, sta, xhr, $form) {
$('#result-code').html(sta);
$('#result-content').html(res);
}
});
<小时/>

正如@Rainer Rillke回复的:解决方案如下,注意错误时收到的参数顺序与成功时收到的参数顺序不同!

$('form').ajaxSubmit({
success: function(res, sta, xhr, $form) {
$('#result-code').html(xhr.status);
$('#result-content').html(res);
},
error: function(xhr) {
$('#result-code').html(xhr.status);
$('#result-content').html(xhr.responseText);
}
});

最佳答案

使用 jqXHRxhr.status 属性.

$('form').ajaxSubmit({
success: function(res, sta, xhr, $form) {
$('#result-code').text(xhr.status);
$('#result-content').html(res);
},
error: function(xhr) {
$('#result-code').text(xhr.status);
}
});

关于javascript - 在 jquery.form.js 中捕获状态代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24027422/

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