When i load a page using jQuery load, if the page that is being loaded has scriptaculous inside, then the page redirects me over and over to itself after it was loaded for the first time. This is my jquery code that i use to load pages:
jQuery( document ).ready(function( $ ) {
// Code that uses jQuery's $ can follow here.
///////////////////////////////////////////////////////////////////////////////
$(document).on('click', 'a[rel*=charger_tout]', function(e) {
e.preventDefault();
var myId_to_update_here = $(this).data('ajax');
var afficher_chargement = $(this).data('icon');
if(afficher_chargement=='Oui')
{
$('#'+myId_to_update_here).html('<img src="images/facebook_style_loader.gif" />');
}
//Fin de l'affichage du chargement si le data-icon='Oui'
$('#'+myId_to_update_here).load($(this).attr('href'), function(responseText, textStatus, XMLHttpRequest) {
if(textStatus == 'error') {
$('#'+myId_to_update_here).html('<p>Oupps.. There was an error making the AJAX request. Maybe your internet connection is slowing down.</p>');
}
});
return false;
});
///////////////////////////////////////////////////////////////////////////////
});
And here the html that link to the page that has to be loaded
<a href="brouillons.php?membre=<?php echo $membre; ?>" rel="charger_tout" data-ajax="id_du_milieu" data-icon="Oui">charger_tout</a>
How to stop the infinite load after the page is loaded for the first time i clicked ?
The solution is to detect if it is an Ajax request or if the script is being loaded normally and if it is an Ajax request, then i do not display scriptaculous else i display it.
if(@$_SERVER['HTTP_X_REQUESTED_WITH']!='' && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
{
//I do not display scriptaculous here
}
else
{
//I can add scriptaculous
}