I have this code requesting some folder info from a mysql DB:
function gotoDir(pmcat_id, pcat_id){
$('#slideshowContainer').html('<img class="loader" src="/javascript/ajax-loader.gif">');
$.post("/publish/includes/content.includes/functions.slideshow.php",
{ updateSlideshowDir: 1, pmcat_id: pmcat_id, pcat_id: pcat_id },
function(data){
$('#pageSlideshow').html(data.content);
}, "json"
);
}
Sometimes the post request times out because of bad internet connection. Is it possible to set a timeout check on $.post() ? Ex: if $.post() uses more then X ms, reload the request.
UPDATE: Looks like I found a solution:
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",
success:function(data) {
if (data == null){
alert('ajax failed. reloading...');
gotoDir(pmcat_id, pcat_id);
} else {
$('#pageSlideshow').html(data.content);
}
}
});
}
Is this a OK way to do this? :S