I have a problem with a speed of mysql query. I have 2 select boxes with country and cities, on first select changes cities on the second, its provided by ajax:
$(document).ready(function()
{
$(".country").change(function()
{
var id=$(this).val();
var dataString = 'id='+ id;
function doAJAX(url) {
$.ajax
({
type: "POST",
url: url,
data: dataString,
cache: false,
success: function(html)
{
$(".city").html(html);
}
});
}
doAJAX('search_ajax.php');
});
});
When is for example spain or russia where is so many cities, showing them took too much time, table cities:fips 2 varchar, city varchar 100, my select :
SELECT city from cities where fips='some value' //for example EN or any ..
I have on column fips index.
Can anobody help mi to speed this up? or is a better solution other than ajax to make live change of select's?? than开发者_C百科ks
Try creating an index on column fips
.
I don't know if it could be marked as a solution, but I solved it by adding a loading gif when its requested from mysql, maybe it will help someone, the function changes to:
function doAJAX(url) {
$(".city").hide(); // hide the select
$("#Div1").show(); // show loading gif
$("#Div1").html('<img src="images/loading2.gif"> Loading...');
$.ajax({
type: "POST",
url: url,
data: dataString,
cache: false,
success: function(html){
$(".city").html(html);
$(".city").show(); // on succes show select
$("#Div1").hide(); // and hide the loading
}
});
}
精彩评论