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