I have this code requesting some folder info from a mysql DB:
function gotoDir(pmcat_id, pcat_id){
$(\'#slideshowContainer\').html(\'
$.ajax has all the functions you need to accomplish what you are asking for:
function gotoDir(pmcat_id, pcat_id) {
$('#slideshowContainer').html('<img class="loader" src="/javascript/ajax-loader.gif">');
$.ajax({
type: "POST",
url: "/publish/includes/content.includes/functions.slideshow.php",
data: { updateSlideshowDir: 1, pmcat_id: pmcat_id, pcat_id: pcat_id },
dataType: "json",
timeout: 500, // in milliseconds
success: function(data) {
// process data here
},
error: function(request, status, err) {
if(status == "timeout") {
gotoDir(pmcat_id, pcat_id);
}
}
});
}
Please note that you don't need to set the timeout option unless you want to trigger the error method after a specific time you want to set.
You should use $.ajax()
and $.ajaxError()
, then with "ajaxComplete" you can check if your request timedout
, or succeded
.
Source: jQuery API