Skip to content
Extraits de code Groupes Projets
Valider 2b291c56 rédigé par cerdic's avatar cerdic
Parcourir les fichiers

Quand un contexte ajax est invalide (corrompu ou trop long, ou on a vide le...

Quand un contexte ajax est invalide (corrompu ou trop long, ou on a vide le cache sur le disque), renvoyer une erreur 400 bad request
+ cote JS traiter le cas d'erreur, marquer le bloc ajax invalide, et rediriger sans ajax si c'etait la nouvelle url de la page
parent d23c72e6
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -205,6 +205,7 @@ function http_status($status) { ...@@ -205,6 +205,7 @@ function http_status($status) {
301 => '301 Moved Permanently', 301 => '301 Moved Permanently',
302 => '302 Found', 302 => '302 Found',
304 => '304 Not Modified', 304 => '304 Not Modified',
400 => '400 Bad Request',
401 => '401 Unauthorized', 401 => '401 Unauthorized',
403 => '403 Forbidden', 403 => '403 Forbidden',
404 => '404 Not Found', 404 => '404 Not Found',
......
...@@ -149,7 +149,7 @@ function traiter_appels_inclusions_ajax() { ...@@ -149,7 +149,7 @@ function traiter_appels_inclusions_ajax() {
} }
} else { } else {
include_spip('inc/headers'); include_spip('inc/headers');
http_status(403); http_status(400);
$texte = _L('signature ajax bloc incorrecte'); $texte = _L('signature ajax bloc incorrecte');
} }
ajax_retour($texte, false); ajax_retour($texte, false);
......
...@@ -518,6 +518,20 @@ jQuery.spip.on_ajax_loaded = function(blocfrag,c,href,history) { ...@@ -518,6 +518,20 @@ jQuery.spip.on_ajax_loaded = function(blocfrag,c,href,history) {
jQuery.spip.updateReaderBuffer(); jQuery.spip.updateReaderBuffer();
} }
jQuery.spip.on_ajax_failed = function(blocfrag,statusCode,href,history) {
// marquer le bloc invalide
jQuery(blocfrag).addClass('invalid');
// si c'est une erreur 400 on a perdu la signature ajax
//console.log("AJAX Erreur");
//console.log(statusCode);
history = history || (history==null);
// quelle que soit l'erreur, on redirige si c'était la nouvelle URL principale de la page
if (history) {
//console.log("On redirige : " + href);
window.location.href = href;
}
}
jQuery.spip.stateId=0; jQuery.spip.stateId=0;
jQuery.spip.setHistoryState = function(blocfrag){ jQuery.spip.setHistoryState = function(blocfrag){
if (!window.history.replaceState) return; if (!window.history.replaceState) return;
...@@ -611,8 +625,9 @@ jQuery.spip.loadAjax = function(blocfrag,url, href, options){ ...@@ -611,8 +625,9 @@ jQuery.spip.loadAjax = function(blocfrag,url, href, options){
if (options.callback && typeof options.callback == "function") if (options.callback && typeof options.callback == "function")
options.callback.apply(blocfrag); options.callback.apply(blocfrag);
}, },
error: function(){ error: function(e){
jQuery.spip.preloaded_urls[url]=''; jQuery.spip.preloaded_urls[url]='';
jQuery.spip.on_ajax_failed(blocfrag,e.status,href,options.history);
} }
}); });
} }
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter