我在通过.ajax错误从控制器捕获错误消息时遇到了一些问题。该脚本由jQuery UI对话框弹出窗口调用。任何帮助都将不胜感激。
下面是我的控制器中的代码片段
Response.StatusCode = (int)HttpStatusCode.BadRequest;
return Content("There was an error in your request.", MediaTypeNames.Text.Plain);下面是jQuery脚本:
function submitFormWithAjax(form) {
form = $(form);
$.ajax({
url: form.attr('action'),
data: form.serialize(),
type: (form.attr('method')),
dataType: 'text',
error: function(data) {
$('#result').html(data);
},
success: function(data) {
$('#result').html(data);
setTimeout("reloadPage()", 500);
}
});
return false;
}error: function(data)未读取返回的错误消息。有什么建议吗?
发布于 2010-10-01 21:40:29
感谢大家的帮助。经过一些试验之后,我弄明白了,我所需要做的就是在jQuery中这样做
error: function(xhr, textStatus, exceptionThrown) {
$('#result').html(xhr.responseText);
},这是控制器中的
Response.StatusCode = (int)HttpStatusCode.BadRequest;
return Content("There was an error in your request.");发布于 2010-09-30 03:48:01
错误回调的签名为function(xmlHttpRequest, textStatus, exceptionThrown)。
也许你看到的是错误的参数?
发布于 2010-09-30 08:53:48
试试这个:
function submitFormWithAjax(form) {
form = $(form);
$.ajax({
url: form.attr('action'),
data: form.serialize(),
type: (form.attr('method')),
dataType: 'text',
error: function(data) {
$('#result').html(data);
},
success: function(xmlHttpRequest, textStatus, exceptionThrown) {
$('#result').html(xmlHttpRequest.statusText);
setTimeout("reloadPage()", 500);
}
});
return false;
}https://stackoverflow.com/questions/3825232
复制相似问题