Précédent   Forum des professionnels en informatique > Webmasters - Développement Web > AJAX
AJAX Forum sur la programmation AJAX. Avant de poster : Cours AJAX, FAQ AJAX, Toutes les FAQ JavaScript
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 01/03/2011, 17h30   #1
Candidat au titre de Membre du Club
 
Homme Romain
Inscription : janvier 2010
Messages : 30
Détails du profil
Informations personnelles :
Nom : Homme Romain
Âge : 21
Localisation : France

Informations forums :
Inscription : janvier 2010
Messages : 30
Points : 13
Points : 13
Par défaut Problèmes de liens

Bonjour à tous,

J'ai récupéré sur le net un petit script qui génère un portfolio en AJAX. J'ai un problème avec les liens vers les différentes pages de ce site.

En effet, j'ai par exemple une page1.html et un bouton qui envoie sur une page2.html

Le href se fait de manière classique: <a href="page2.html">...</a>

Cependant, dans la barre d'adresse de mon navigateur, l'url apparait en tant que http://monsite.fr/#page2

Comment faire pour afficher une url "standard" du type monsite.fr/page2.html ?

Je vous remercie d'avance
tR4x- est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/03/2011, 08h20   #2
Responsable Développement Web

 
Avatar de Bovino
 
Homme Didier Mouronval
Développeur Web
Inscription : juin 2008
Messages : 13 805
Détails du profil
Informations personnelles :
Nom : Homme Didier Mouronval
Âge : 41
Localisation : France, Gironde (Aquitaine)

Informations professionnelles :
Activité : Développeur Web
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : juin 2008
Messages : 13 805
Points : 35 807
Points : 35 807
Citation:
Envoyé par tR4x-
Comment faire pour afficher une url "standard" du type monsite.fr/page2.html ?
De la magie ?

Ou sinon, nous montrer ton code.
__________________
Pas de question technique par MP !
Tout le monde peut participer à developpez.com, vous avez une idée, contactez-moi !
Vous possédez un blog et aimeriez diffuser vos billets sur le forum, contactez-moi !
Mes formations video2brain : La formation complète sur JavaScriptJavaScript et le DOM par la pratiquePHP 5 et MySQL : les fondamentaux
Mon livre sur jQuery
Bovino est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/03/2011, 10h47   #3
Candidat au titre de Membre du Club
 
Homme Romain
Inscription : janvier 2010
Messages : 30
Détails du profil
Informations personnelles :
Nom : Homme Romain
Âge : 21
Localisation : France

Informations forums :
Inscription : janvier 2010
Messages : 30
Points : 13
Points : 13
Bonjour,

Voici mon fichier .js

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
$(document).ready(function() {
 
	var hash = window.location.hash.substr(1);
	var href = $('#nav li a').each(function(){
		var href = $(this).attr('href');
		if(hash==href.substr(0,href.length-5)){
			var toLoad = hash+'.html #content';
			$('#content').load(toLoad)
		}											
	});
 
	$('#nav li a').click(function(){
 
		var toLoad = $(this).attr('href')+' #content';
		$('#content').hide('fast',loadContent);
		$('#load').remove();
		$('#wrapper').append('<span id="load">LOADING...</span>');
		$('#load').fadeIn('normal');
		window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
		function loadContent() {
			$('#content').load(toLoad,'',showNewContent())
		}
		function showNewContent() {
			$('#content').show('normal',hideLoader());
		}
		function hideLoader() {
			$('#load').fadeOut('normal');
		}
		return false;
 
	});
 
});
Cordialement
tR4x- est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/03/2011, 21h40   #4
Rédacteur/Modérateur
 
Avatar de marcha
 
Homme Marc Chappuis
Développeur Web
Inscription : décembre 2003
Messages : 1 535
Détails du profil
Informations personnelles :
Nom : Homme Marc Chappuis
Âge : 41
Localisation : Suisse

Informations professionnelles :
Activité : Développeur Web

Informations forums :
Inscription : décembre 2003
Messages : 1 535
Points : 2 206
Points : 2 206
Salut,

Le principe même de ce script est de charger du contenu sans recharger
la globalité de la page. Hors si tu modifies l'url de ton navigateur autrement
qu'en jouant sur l'ancre #... tu vas provoquer un rechargement de page
et l'utilisation d'Ajax dans ce cas devient obsolète.
__________________
Si ton code fait plus d'une ligne, c'est que tu as mal choisi ton langage !
marcha est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/03/2011, 11h57   #5
Candidat au titre de Membre du Club
 
Homme Romain
Inscription : janvier 2010
Messages : 30
Détails du profil
Informations personnelles :
Nom : Homme Romain
Âge : 21
Localisation : France

Informations forums :
Inscription : janvier 2010
Messages : 30
Points : 13
Points : 13
Salut,

J'avais bien compris que l'interet de ce script est de réaliser cela, cependant je veux ajouter un slideshow en flash sur une des pages de mon site, et lorsque je clique depuis la page d'index sur le lien vers la page en question, la modification n'est pas visible. Or, lorsque je tape directement xxx.fr/mapage.html dans ma barre d'url la modification est ok.

Autre chose bizarre, si je modifie juste du texte sur ma page, la modification est visible meme lorsque j'atteinds la page avec le #, mais des que je mets le code de mon slideshow, rien ne change.

Pourquoi à votre avis ?

Merci beaucoup de votre aide
tR4x- est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/03/2011, 13h34   #6
Rédacteur/Modérateur
 
Avatar de marcha
 
Homme Marc Chappuis
Développeur Web
Inscription : décembre 2003
Messages : 1 535
Détails du profil
Informations personnelles :
Nom : Homme Marc Chappuis
Âge : 41
Localisation : Suisse

Informations professionnelles :
Activité : Développeur Web

Informations forums :
Inscription : décembre 2003
Messages : 1 535
Points : 2 206
Points : 2 206
On peut voir ça en ligne quelque part ?
__________________
Si ton code fait plus d'une ligne, c'est que tu as mal choisi ton langage !
marcha est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/03/2011, 15h25   #7
Candidat au titre de Membre du Club
 
Homme Romain
Inscription : janvier 2010
Messages : 30
Détails du profil
Informations personnelles :
Nom : Homme Romain
Âge : 21
Localisation : France

Informations forums :
Inscription : janvier 2010
Messages : 30
Points : 13
Points : 13
Dans le but d'avoir moins de code à afficher ici, je veux juste ici un apercu d'une image lors d'un clic sur un lien textuel (le tout en JavaScript toujours grace à la librairie Slimbox)

Apercu du résultat de Slimbox: http://www.digitalia.be/demo/slimbox/

-------------------

Voila mon index.html

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="css.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/slimbox2.css" type="text/css" media="screen" />
<title>blabla</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="js.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript" src="js/slimbox2.js"></script>
</head>
<body>
    <div id="wrapper">
    <ul id="nav">
        <li><a href="index.html">Accueil</a></li>
        <li><a href="about.html">Infos</a></li>
        <li><a href="cv.html">CV &amp; Projets</a></li>
        <li><a href="contact.html">Contact</a></li>
    </ul>
</div>
</body>
</html>
La page cv.html

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="css.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/slimbox2.css" type="text/css" media="screen" />
<title>blabla</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="js.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript" src="js/slimbox2.js"></script>
</head>
<body>
    <div id="wrapper">
    <ul id="nav">
        <li><a href="index.html">Accueil</a></li>
        <li><a href="about.html">Infos</a></li>
        <li><a href="cv.html">CV &amp; Projets</a></li>
        <li><a href="contact.html">Contact</a></li>
    </ul>
    <div id="content">
        <h2>Curriculum Vitae</h2>
        <center><a href="img.jpg" rel="lightbox">Voir un apercu</a></center>
</div>
</div>
</body>
</html>
Le fichier slimbox2.js

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 
/*
	Slimbox v2.04 - The ultimate lightweight Lightbox clone for jQuery
	(c) 2007-2010 Christophe Beyls <http://www.digitalia.be>
	MIT-style license.
*/
(function(w){var E=w(window),u,f,F=-1,n,x,D,v,y,L,r,m=!window.XMLHttpRequest,s=[],l=document.documentElement,k={},t=new Image(),J=new Image(),H,a,g,p,I,d,G,c,A,K;w(function(){w("body").append(w([H=w('<div id="lbOverlay" />')[0],a=w('<div id="lbCenter" />')[0],G=w('<div id="lbBottomContainer" />')[0]]).css("display","none"));g=w('<div id="lbImage" />').appendTo(a).append(p=w('<div style="position: relative;" />').append([I=w('<a id="lbPrevLink" href="#" />').click(B)[0],d=w('<a id="lbNextLink" href="#" />').click(e)[0]])[0])[0];c=w('<div id="lbBottom" />').appendTo(G).append([w('<a id="lbCloseLink" href="#" />').add(H).click(C)[0],A=w('<div id="lbCaption" />')[0],K=w('<div id="lbNumber" />')[0],w('<div style="clear: both;" />')[0]])[0]});w.slimbox=function(O,N,M){u=w.extend({loop:false,overlayOpacity:0.8,overlayFadeDuration:400,resizeDuration:400,resizeEasing:"swing",initialWidth:250,initialHeight:250,imageFadeDuration:400,captionAnimationDuration:400,counterText:"Image {x} of {y}",closeKeys:[27,88,67],previousKeys:[37,80],nextKeys:[39,78]},M);if(typeof O=="string"){O=[[O,N]];N=0}y=E.scrollTop()+(E.height()/2);L=u.initialWidth;r=u.initialHeight;w(a).css({top:Math.max(0,y-(r/2)),width:L,height:r,marginLeft:-L/2}).show();v=m||(H.currentStyle&&(H.currentStyle.position!="fixed"));if(v){H.style.position="absolute"}w(H).css("opacity",u.overlayOpacity).fadeIn(u.overlayFadeDuration);z();j(1);f=O;u.loop=u.loop&&(f.length>1);return b(N)};w.fn.slimbox=function(M,P,O){P=P||function(Q){return[Q.href,Q.title]};O=O||function(){return true};var N=this;return N.unbind("click").click(function(){var S=this,U=0,T,Q=0,R;T=w.grep(N,function(W,V){return O.call(S,W,V)});for(R=T.length;Q<R;++Q){if(T[Q]==S){U=Q}T[Q]=P(T[Q],Q)}return w.slimbox(T,U,M)})};function z(){var N=E.scrollLeft(),M=E.width();w([a,G]).css("left",N+(M/2));if(v){w(H).css({left:N,top:E.scrollTop(),width:M,height:E.height()})}}function j(M){if(M){w("object").add(m?"select":"embed").each(function(O,P){s[O]=[P,P.style.visibility];P.style.visibility="hidden"})}else{w.each(s,function(O,P){P[0].style.visibility=P[1]});s=[]}var N=M?"bind":"unbind";E[N]("scroll resize",z);w(document)[N]("keydown",o)}function o(O){var N=O.keyCode,M=w.inArray;return(M(N,u.closeKeys)>=0)?C():(M(N,u.nextKeys)>=0)?e():(M(N,u.previousKeys)>=0)?B():false}function B(){return b(x)}function e(){return b(D)}function b(M){if(M>=0){F=M;n=f[F][0];x=(F||(u.loop?f.length:0))-1;D=((F+1)%f.length)||(u.loop?0:-1);q();a.className="lbLoading";k=new Image();k.onload=i;k.src=n}return false}function i(){a.className="";w(g).css({backgroundImage:"url("+n+")",visibility:"hidden",display:""});w(p).width(k.width);w([p,I,d]).height(k.height);w(A).html(f[F][1]||"");w(K).html((((f.length>1)&&u.counterText)||"").replace(/{x}/,F+1).replace(/{y}/,f.length));if(x>=0){t.src=f[x][0]}if(D>=0){J.src=f[D][0]}L=g.offsetWidth;r=g.offsetHeight;var M=Math.max(0,y-(r/2));if(a.offsetHeight!=r){w(a).animate({height:r,top:M},u.resizeDuration,u.resizeEasing)}if(a.offsetWidth!=L){w(a).animate({width:L,marginLeft:-L/2},u.resizeDuration,u.resizeEasing)}w(a).queue(function(){w(G).css({width:L,top:M+r,marginLeft:-L/2,visibility:"hidden",display:""});w(g).css({display:"none",visibility:"",opacity:""}).fadeIn(u.imageFadeDuration,h)})}function h(){if(x>=0){w(I).show()}if(D>=0){w(d).show()}w(c).css("marginTop",-c.offsetHeight).animate({marginTop:0},u.captionAnimationDuration);G.style.visibility=""}function q(){k.onload=null;k.src=t.src=J.src=n;w([a,g,c]).stop(true);w([I,d,g,G]).hide()}function C(){if(F>=0){q();F=x=D=-1;w(a).hide();w(H).stop().fadeOut(u.overlayFadeDuration,j)}return false}})(jQuery);
 
// AUTOLOAD CODE BLOCK (MAY BE CHANGED OR REMOVED)
if (!/android|iphone|ipod|series60|symbian|windows ce|blackberry/i.test(navigator.userAgent)) {
	jQuery(function($) {
		$("a[rel^='lightbox']").slimbox({/* Put custom options here */}, null, function(el) {
			return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
		});
	});
}
et la feuille de style Slimbox2.css

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
 
/* SLIMBOX */
 
#lbOverlay {
	position: fixed;
	z-index: 9999;
	left: 0;
	top: 0;
	width: 100%;
	height: 100%;
	background-color: #000;
	cursor: pointer;
}
 
#lbCenter, #lbBottomContainer {
	position: absolute;
	z-index: 9999;
	overflow: hidden;
	background-color: #fff;
}
 
.lbLoading {
	background: #fff url(loading.gif) no-repeat center;
}
 
#lbImage {
	position: absolute;
	left: 0;
	top: 0;
	border: 10px solid #fff;
	background-repeat: no-repeat;
}
 
#lbPrevLink, #lbNextLink {
	display: block;
	position: absolute;
	top: 0;
	width: 50%;
	outline: none;
}
 
#lbPrevLink {
	left: 0;
}
 
#lbPrevLink:hover {
	background: transparent url(prevlabel.gif) no-repeat 0 15%;
}
 
#lbNextLink {
	right: 0;
}
 
#lbNextLink:hover {
	background: transparent url(nextlabel.gif) no-repeat 100% 15%;
}
 
#lbBottom {
	font-family: Verdana, Arial, Geneva, Helvetica, sans-serif;
	font-size: 10px;
	color: #666;
	line-height: 1.4em;
	text-align: left;
	border: 10px solid #fff;
	border-top-style: none;
}
 
#lbCloseLink {
	display: block;
	float: right;
	width: 66px;
	height: 22px;
	background: transparent url(closelabel.gif) no-repeat center;
	margin: 5px 0;
	outline: none;
}
 
#lbCaption, #lbNumber {
	margin-right: 71px;
}
 
#lbCaption {
	font-weight: bold;
}
Je rappelle que lorsque je tape directement mon url ca marche. Mais pas lors du clic sur "CV & Projets" depuis ma page d'index.

Un grand merci d'avance
tR4x- est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/03/2011, 16h16   #8
Rédacteur/Modérateur
 
Avatar de marcha
 
Homme Marc Chappuis
Développeur Web
Inscription : décembre 2003
Messages : 1 535
Détails du profil
Informations personnelles :
Nom : Homme Marc Chappuis
Âge : 41
Localisation : Suisse

Informations professionnelles :
Activité : Développeur Web

Informations forums :
Inscription : décembre 2003
Messages : 1 535
Points : 2 206
Points : 2 206
Salut,

A mon avis le problème vient de l'initialisation de slimbox

Dans slimbox2.js tu as la méthode slimbox qui est appliquée
à tous les liens qui ont un attribut rel qui commence par lightbox

Code :
1
2
3
4
 
$("a[rel^='lightbox']").slimbox({/* Put custom options here */}, null, function(el) {
			return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
		});
Je pense que slimbox ajoute des évènement onclick sur ces liens directement
dans le DOM. Si bien que quand tu charge ton contenu de page avec ajax
les liens sont bien chargés, mais aucun évènement ne leur est associé car
slimbox2.js a été exécuté avant que tes liens ne figurent dans le DOM et
n'est pas exécuté à nouveau.

Si c'est bien là le problème, tu as deux solutions simples

1) tu place le code d'initialisation de slimbox dans une balise script
que tu mets dans le contenu de ta page galerie (a la fin du fragment html qui est chargé)

Code :
1
2
3
4
5
6
7
8
9
 
<a rel='lightbox'>...</a>
<a rel='lightbox'>...</a>
<a rel='lightbox'>...</a>
<script type='text/javascript'>
$("a[rel^='lightbox']").slimbox({/* Put custom options here */}, null, function(el) {
			return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
		});
</script>
Jquery execute les scripts qu'ils trouvent dans le réponse après un .load

2) Tu modifie le code de chargement de tes pages pour lancer une initialisation de slimbox après chaque chargement

Code :
1
2
3
4
5
6
7
8
9
 
function loadContent() {
	$('#content').load(toLoad, function() {
		$("a[rel^='lightbox']").slimbox({}, null, function(el) {
			return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
		});
		showNewContent();
	});
}
A mon avis ton code de chargement Ajax a un petit bug: les parenthèses
à la fin de showNewContent devraient pas être là. En effet, load attend
une référence à une fonction qu'il appellera à la fin du chargement du
fragment et dans ton code la fonction est appelée imédiatement et c'est
son résultat qui est passé en paramètre à load.

Idem pour le hideLoader (mais j'ai pas testé chez moi)

Code :
1
2
3
4
 
	function loadContent() {
		$('#content').load(toLoad,'',showNewContent)
	}
__________________
Si ton code fait plus d'une ligne, c'est que tu as mal choisi ton langage !
marcha est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/03/2011, 18h01   #9
Candidat au titre de Membre du Club
 
Homme Romain
Inscription : janvier 2010
Messages : 30
Détails du profil
Informations personnelles :
Nom : Homme Romain
Âge : 21
Localisation : France

Informations forums :
Inscription : janvier 2010
Messages : 30
Points : 13
Points : 13
Un grand merci à toi, ca marche pour l'affichage de l'image !

Maintenant, j'aimerais faire de même avec ma galerie flash, pour cela j'utilise SimpleViewer.

Seulement, meme probleme qu'avant et je ne sais pas quel bout de code mettre ou.

Si tu pouvais m'aider, ce serait génial. Voici le .zip de ma galerie flash:

http://www.simpleviewer.net/downloads/simpleviewer.zip

Encore MERCI !
tR4x- est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/03/2011, 09h47   #10
Candidat au titre de Membre du Club
 
Homme Romain
Inscription : janvier 2010
Messages : 30
Détails du profil
Informations personnelles :
Nom : Homme Romain
Âge : 21
Localisation : France

Informations forums :
Inscription : janvier 2010
Messages : 30
Points : 13
Points : 13
Je vais tenter d'etre plus précis.

La ligne de code me permettant d'initialiser ma galerie est celle ci:

Code :
SV.simpleviewer.load('sv-container', '100%', '100%', '222222', true);
J'ai donc modifié mon fichier js.js en essayant de reprendre un peu la méthode de marcha.
L'id de la balise <div> qui doit contenir ma galerie est sv-container

Voila ce que ca donne:

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
$(document).ready(function() {
 
	var hash = window.location.hash.substr(1);
	var href = $('#nav li a').each(function(){
		var href = $(this).attr('href');
		if(hash==href.substr(0,href.length-5)){
			var toLoad = hash+'.html #content';
			var gallery = hash+'.html #sv-container';
			loadContent();
			loadGallery();
		}											
	});
 
	$('#nav li a').click(function(){
 
		var toLoad = $(this).attr('href')+' #content';
		$('#content').hide('fast',loadContent);
		$('#load').remove();
		$('#wrapper').append('<span id="load">LOADING...</span>');
		$('#load').fadeIn('normal');
		window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
 
		function loadGallery() {
		$('#sv-container').load(gallery, function() {
		jQuery(document).ready(function () {
		SV.simpleviewer.load('sv-container', '100%', '100%', '222222', true);
	});
	showNewContent();
	});
		}
 
		function loadContent() {
	$('#content').load(toLoad, function() {
		$("a[rel^='lightbox']").slimbox({}, null, function(el) {
			return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
		});
		showNewContent();
	});
}
		function showNewContent() {
			$('#content').show('normal',hideLoader());
			$('#sv-container').show('normal',hideLoader());
		}
		function hideLoader() {
			$('#load').fadeOut('normal');
		}
		return false;
 
	});
 
});
Mais cela n'a aucun effet Help please ! Merci
tR4x- est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/03/2011, 10h11   #11
Rédacteur/Modérateur
 
Avatar de marcha
 
Homme Marc Chappuis
Développeur Web
Inscription : décembre 2003
Messages : 1 535
Détails du profil
Informations personnelles :
Nom : Homme Marc Chappuis
Âge : 41
Localisation : Suisse

Informations professionnelles :
Activité : Développeur Web

Informations forums :
Inscription : décembre 2003
Messages : 1 535
Points : 2 206
Points : 2 206
La ligne jQuery(document).ready(function () dans ta callback de load
est inutile. En effet, load appelle la callback une fois le fragment chargé
injecté dans le DOM.

Mais à mon avis ton problème vient de ton code de chargement. Il te faut
comprendre la différence entre ces deux notations:

Code :
1
2
3
4
5
 
function toto() {
};
 
$('id').load(url, toto());
et

Code :
1
2
3
4
5
 
function toto() {
};
 
$('id').load(url, toto);
La première notation est fausse. La fonction load de JQuery attends
une référence à une fonction comme paramètre.

load utilise cette référence pour appeler la fonction au moment approprié.
c'est à dire quand la réponse a été reçue et que le fragment html a été
placé dans le document.

Dans la première notation ci-dessus, toto() est appelé avant même que
la requête ajax n'aie été lancée. car les parenthèses après le nom d'une
fonction provoque un appel à celle-ci. et c'est le résultat de la fonction
qui est passé à load.

Je te propose de placer des alert dans ton code et d'observer le réseau
avec FireBug afin de t'assurer que les opérations se passent dans l'ordre
voulu. Car si tu initialise ta galerie avant qu'elle ne soit chargée, ça va pas
le faire.
__________________
Si ton code fait plus d'une ligne, c'est que tu as mal choisi ton langage !
marcha est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/03/2011, 17h45   #12
Candidat au titre de Membre du Club
 
Homme Romain
Inscription : janvier 2010
Messages : 30
Détails du profil
Informations personnelles :
Nom : Homme Romain
Âge : 21
Localisation : France

Informations forums :
Inscription : janvier 2010
Messages : 30
Points : 13
Points : 13
Merci de ces précisions.

En conséquence, j'ai modifié mon fichier .js

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
$(document).ready(function() {
 
	var hash = window.location.hash.substr(1);
	var href = $('#nav li a').each(function(){
		var href = $(this).attr('href');
		if(hash==href.substr(0,href.length-5)){
			var toLoad = hash+'.html #content';
			var gallery = hash+'.html #sv-container';
			$('#content').load(toLoad)
			$('#sv-container').load(gallery)
		}											
	});
 
	$('#nav li a').click(function(){
 
		var toLoad = $(this).attr('href')+' #content';
		$('#content').hide('fast',loadContent);
		$('#load').remove();
		$('#wrapper').append('<span id="load">LOADING...</span>');
		$('#load').fadeIn('normal');
		window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
		function loadContent() {
	$('#content').load(toLoad, function() {
		$("a[rel^='lightbox']").slimbox({}, null, function(el) {
			return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
		});
		showNewContent();
	});
}
 
		function loadGallery() {
		$('#sv-container').load(gallery, function() {
		SV.simpleviewer.load('sv-container', '100%', '100%', '222222', true);
		showNewContent();
		});
		}
 
		function showNewContent() {
			$('#content').show('normal',hideLoader());
			$('#sv-container').show('normal',hideLoader());
		}
		function hideLoader() {
			$('#load').fadeOut('normal');
		}
		return false;
 
	});
 
});
résultat: toujours pareil :/

J'ai alors essayé de rajouter ces 2 lignes

Code :
1
2
var gallery = $(this).attr('href')+' #sv-container';
$('#sv-container').hide('fast',loadGallery);
Et la, la galerie s'affiche 1 fois sur 2, aléatoirement, mais par contre d'autres pages ne s'affichent plus, bref je ne comprends pas trop. Je suis un peu paumé maintenant :S

En espérant y voir plus clair, encore merci
tR4x- est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 14h49.


 
 
 
 
Partenaires

Hébergement Web