IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

jQuery Discussion :

Requete ajax trop lente


Sujet :

jQuery

  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    144
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 144
    Par défaut Requete ajax trop lente
    Bonjour,

    J'interroge ma bdd via une requete AJAX

    Mais des qu'il y a trop de resultats a afficher ça rame dur, voir ça plante.

    Voici mon code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    <?php
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
    <head>
        <title>Titre de la page</title>
        <meta name="keywords" lang="fr" content="motcle1,mocle2" />
        <meta name="description" content="Description de ma page web." />
        <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1""/>
        <meta http-equiv="Content-Language" content="fr" />
        <meta http-equiv="Content-Script-Type" content="text/javascript" />
        <link href="styles/style_menu.css" rel="stylesheet" type="text/css" />
    	<link href="styles/styles.css" rel="stylesheet" type="text/css" />
    	<script type="text/javascript" language="Javascript" src="js/jquery.js"></script>
    	<script type="text/javascript">
    	$(function(){
    	$("#loc").val(32);
    	$("#loc").keyup(function (){
    	var varatrans = ($("#loc").val());
    	var type;
    	var longch;
    	 if(isNaN(varatrans))
    	{
    	type = "string";
    	$("#loc").attr("maxlength","50");
    	}
    	else
    	{
    		type = "num";
    		//varatrans = $.trim(varatrans.replace(/[\s]/gi,""));
    		$("#loc").val(varatrans);
    		$("#loc").attr("maxlength","5");
    	}
     
    	longch = varatrans.length;
    		$("#code_pos").empty();
    			$.ajax({
       			type:"POST",
       			url:"test.php",
       			data:"varatrans=" + varatrans + "&type=" + type + "&longch=" + longch,
    			dataType:"json",
       			success: function(tableau){
     
    				var villages = tableau[varatrans];
    				if (typeof villages != "undefined")
    				{
     
    					for(var key in villages) {
    					$("#code_pos").show();
    					$("#code_pos").append('<p><a href="#" >' + villages[key] + '</a></p>');
    					$("#code_pos a").click(function (){
    					$("#loc").val($(this).text());
    					$("#code_pos").hide();
    					});
     
    				}
    				}
    				else
    				{
    				$("#code_pos").hide();
    				}
     
     
      			}
    			});
    	});
     
    	$("#search").submit(function (){
    		var cat = $('input[type=radio][name=cat]:checked').attr('value');
     		var varatrans = ($("#loc").val());
    			if (typeof cat == "undefined")
    			{
    				$("#error").text("Choisissez une catégorie (Achat, Location, ...)");
    				$("#error").show();
    			}
    			else
    			{
    			$.ajax({
                	type: "POST",
                	url: "annonces-immobilieres.php",
                	data: "cat="+cat+ "&varantrans=" +varantrans,
                	dataType: "json",
                });
     
    			}
    			return false;
    	});
     
     
    	$("#contprixsurf input").bind('keyup blur',function (){
    	var valinput = $(this).val();
    		if(isNaN(valinput))
    		{
    			valinput = $.trim(valinput.replace(/[^0-9]/gi,""));
    			$(this).val(valinput);
    		}
    	});
     
     
     
     
    });
     
    	</script>
    	<style>
    	#head{width:980px;height:80px;background-image:url(grafs/logofirst.jpg);background-repeat:no-repeat;}
    	#cont_menu{width:980px;height:40px;}
    	#cont_menu div {float:left;border:1px solid red;margin-right:10px;color:green;padding:15px;padding-top:3px;padding-bottom:3px;}
    	#cont_loc{width:400px;height:30px;background:url(grafs/fond_loc.gif);margin-left:10px;margin-top:20px;}
    	#loc, #forloc{margin-left:10px;color:#009900;font-weight:bold;}
    	#loc{width:280px;margin-top:4px;}
    	#forloc{color:#009900;}
    	#code_pos{width:auto;height:auto;max-height:300px;overflow-y:scroll;position:absolute;border:2px solid #009900;border-top:none;padding:10px;margin-top:-70px;margin-left:140px;background:white;display:none;}
    	#code_pos a{color:#009900;font-weight:bold;}
    	#code_pos p{height:10px;}
    	#ex a{margin-left:10px;font-style:italic;color:#009900;}
    	#prixsurf label{text-align:right;display:block;float:left;width:100px;height:14px;font-weight:bold;color:#009900;}
    	#prixsurf input{float:left;height:14px;width:60px;border:1px solid #009900;margin-left:5px;color:#009900;}
    	#surf label{text-align:right;display:block;float:left;width:100px;height:14px;font-weight:bold;color:#009900;}
    	#surf input{float:left;height:14px;width:60px;border:1px solid #009900;margin-left:5px;color:#009900;}
     
    	#but_search{width:200px;height:24px;color:black;font-weight:bold;margin-top:30px;background:url(grafs/but_loc.gif);}
    	</style>
    </head>
    <html>
    <body>
     
    <div id="cont_princ" style="width:980px;height:auto;background:lightyellow;">
    	<a href="#"><div id="head" style=""></div></a>
    	<div id="connect" style="width:980px;height:50px;border:1px solid red;padding-bottom:5px;background:grey;">
    		<form method="post" action="connex_mb.php" id="connex_util">
       			<p>
           			<label for="login">Login</label><input type="text" name="login" id="login" size="10" maxlength="8" />
    				<label for="mpasse">Mot de passe</label><input type="password" name="mpasse" id="mpasse" size="10" maxlength="8" />
       			</p>
    		</form>
    	</div>
     
     
    	<form method="post" action="redirect.php" id="search">
    	<div style="width:980px;height:640px;background:red;position:relative;">
    		<div id="cont_menu">
    			<div><input type="radio" name="cat" value="ach" />Achat</div>
    			<div><input type="radio" name="cat" value="loc" />Location</div>
    			<div><input type="radio" name="cat" value="via" />Viager</div>
    			<div><input type="radio" name="cat" value="ime" />Immobilier d'entreprise</div>
    			<div><input type="radio" name="cat" value="fdc" />Fonds de commerce</div>
    			<div><input type="radio" name="cat" value="vac" />Vacances</div>
    		</div>
    		<div style="width:980px;height:600px;background:yellow;">
    			<div style="width:160px;height:600px;background:black;float:left;">
    			</div>
    			<div style="width:660px;height:600px;background:white;float:left;">
    				<div style="width:460px;height:40px;">
    					<div id="error" style="position:absolute;width:440px;height:20px;border:2px solid red;display:none;margin-left:10px;margin-top:20px;padding:5px;"></div>
    				</div>
    				<div style="width:460px;height:100px;">
    					<div id="cont_loc"><label id="forloc" for="loc">Localisation</label><input type="text" autocomplete="off" name="loc" id="loc" maxlength="40" /></div>
    					<div id="ex" style="margin-left:20px;color:#009900;">Ex: <a href="#">Auch</a><a href="#">Mirande</a><a href="#">Riscle</a><a href="#">32290</a></div>
    				</div>
     
    				<div id="code_pos"></div>
    				<div id="contprixsurf" style="width:460px;margin-top:10px;">
    					<div id="prixsurf" style="width:420px;height:30px;margin-left:20px;">
    						<label id="forpricemin" for="pricemin">Prix Min</label><input type="text" name="pricemin" id="pricemin" maxlength="10" />€
    						<label id="forpricemax" for="pricemax">Prix Max</label><input type="text" name="pricemax" id="pricemax" maxlength="10" />
    					</div>
    					<div id="surf" style="width:420px;height:50px;margin-left:20px;">
    						<label id="forsurfmin" for="surfmin">Surface Min</label><input type="text" name="surfmin" id="surfmin" maxlength="10" />m²
    						<label id="forsurfmax" for="surfmax">Surface Max</label><input type="text" name="surfmax" id="surfmax" maxlength="10" />
     
    					</div>
    					<div style="width:460px;text-align:center;"><input value="RECHERCHE >>>" id="but_search" tabindex="50" type="image" src="grafs/but_loc.gif"/></div>
    				</div>
     
    			</div>
    			<div style="width:160px;height:600px;background:black;float:left;">
    			</div>
    		</div>
    	</div>
    	</form>
    	<div style="width:980px;height:200px;background:green;"></div>
    </div>
    </body>
    </html>
    Par avance merci

  2. #2
    Rédacteur

    Avatar de Bovino
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2008
    Messages
    23 647
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France, Gironde (Aquitaine)

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

    Informations forums :
    Inscription : Juin 2008
    Messages : 23 647
    Billets dans le blog
    20
    Par défaut
    Ben... à priori, JavaScript n'y est pour rien, il se contente d'envoyer la requête et d'attendre la réponse.
    C'est probablement ton script PHP qui est en cause.
    Pas de question technique par MP !
    Tout le monde peut participer à developpez.com, vous avez une idée, 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
    Module Firefox / Chrome d'intégration de JSFiddle et CodePen sur le forum

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    144
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 144
    Par défaut
    Je poste ici mon script php afin de mieux cerner le probleme :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    <?php
    require_once ('incl_php/inc_connex.inc');
    mysql_query("SET NAMES 'utf8'");
    mysql_select_db('gersimmo_db') OR die('Sélection de la base impossible');
    $tableau = array();
     
     
    $varatrans = $_POST['varatrans'];
    $type = $_POST['type'];
    $longch= $_POST['longch'];
     
    if (is_numeric($varatrans)) 
    {
            $sql = "SELECT * FROM test WHERE value like '$varatrans%'";
    }
    else
    {
            $sql = "SELECT * FROM test WHERE nom_ville like '$varatrans%'";
    }
            $req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
     
            $resultat=mysql_query($req); 
            $i = 0;
            while($ligne = mysql_fetch_array($req))
            {
                    $i++;
                    $id=$ligne['id'];
                    $codes = $ligne['value'];
                    $nom_ville = $ligne['nom_ville'];
                    $tableau [$varatrans][]= array($nom_ville." "."(".$codes.")");
            }  
            
    echo json_encode($tableau);
    ?>

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Mars 2011
    Messages
    52
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2011
    Messages : 52
    Par défaut
    salut

    mets un LIMIT dans ta requête mysql.

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    144
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 144
    Par défaut
    Un limit ne permettrait pas d'afficher tous les codes postaux ou villes ... si j ai bien compris.

    La solution serait, peut etre, de placer un preloader mais dans ce cas precis, je ne vois pas comment faire

  6. #6
    Membre confirmé
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    144
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 144
    Par défaut
    N ayant toujours pas trouvé de solution adéquate, je me permet de remonter ce post

Discussions similaires

  1. [AC-2003] Requete ACCESS trop lente par rapport a SQL SERVER 2005
    Par apnw7931 dans le forum Requêtes et SQL.
    Réponses: 6
    Dernier message: 07/03/2011, 18h48
  2. [MySQL] requete trop lente
    Par mademoizel dans le forum PHP & Base de données
    Réponses: 23
    Dernier message: 10/08/2010, 23h03
  3. Problème de requete trop lente , je cherche une alternative
    Par mobscene dans le forum MS SQL Server
    Réponses: 4
    Dernier message: 02/05/2007, 10h39
  4. pb requete trop lente.(tables sans relation)
    Par zeloutre dans le forum Requêtes et SQL.
    Réponses: 2
    Dernier message: 27/04/2007, 08h48
  5. requete trop lente
    Par ob1knob dans le forum Requêtes et SQL.
    Réponses: 5
    Dernier message: 16/03/2007, 18h21

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo