Jump to content

Recommended Posts

I have a search where it shows suggestions for friends to add, it works fine the only problem it loads slowly and returns wrong data (in the order that it would return as you type) because it  when you type each letter it sends a new search so what its doing is:

 

you type: D

sends query to database....then returns results for that query

you type: Dago

it sends query for D, then returns that, then it sends query for Da, then returns that, then sends query for Dag, then returns that, then sends query for Dago, then returns that.

how can i cancel the others so it's smooth and fast and doesn't return wrong data?

 

this is my code:

function search_suggestions()
{
var check_data = encodeURIComponent($(".search").val());
var search_val = check_data.replace(/^\s+|\s+$/g, '');
if(search_val&&search_val!=$(".search").attr('title'))
{

$(".search-suggestions").css({"display": "block"});
//$(".search-button").attr("href", "#/findfriends&find="+search_val);
$.ajax({
type: "POST",
url: "ajax/search_suggestion.php",
data: "search="+search_val,
cache: false,
success: function(html){
$(".search-suggestion-results").html(html);
}
});

}
else
{
$(".search-suggestions").css({"display": "none"});	
//$(".search-button").removeAttr("href");
}

}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.