Hi there!
I have a function that handles all of the form submit functions on a page that uses the jQuery ajax api to submit the request asynchronously and then update a particular
Here is my code:
Currently, the items are refreshed every 5 seconds after a submit to the server and it works fine under normal conditions.
However, when an error occurs, I want to display the error details to the user.
To test this I stopped the server process completely to cause a "server unavailable" error.
In the error function, the textStatus parameter contains text "error" which is not very informative. I would have expected the errorThrown to contain information about the error (in this case: server not available or the HTTP status code) but it contains nothing.
Is there a way to display more information about the error to the user?
How do I retrieve this information?
Thanks,
-Frinny
I have a function that handles all of the form submit functions on a page that uses the jQuery ajax api to submit the request asynchronously and then update a particular
<div> on the page.Here is my code:
Code:
function Refresh() {
$(document.forms[0]).submit();
}
$(document).ready(function () {
$(document).on("submit", "form", function (event) {
event.preventDefault();
var form = $(this);
$.ajax({
type: this.method,
url: this.action,
data: form.serialize(),
cache: false,
success: function (result) {
var lastRefreshed = new Date();
var str = lastRefreshed.toString() + result;
$('#itemsContent').html(str);
},
complete: function () {
window.setTimeout(Refresh, 5000);
},
error: function (jqXHR, textStatus, errorThrown) {
var lastRefreshed = new Date();
var str = lastRefreshed.toString() +"<br /><br />"+errorThrown;
$('#itemsContent').html(str);
}
});
});
});
However, when an error occurs, I want to display the error details to the user.
To test this I stopped the server process completely to cause a "server unavailable" error.
In the error function, the textStatus parameter contains text "error" which is not very informative. I would have expected the errorThrown to contain information about the error (in this case: server not available or the HTTP status code) but it contains nothing.
Is there a way to display more information about the error to the user?
How do I retrieve this information?
Thanks,
-Frinny
Comment