How is it possible to make live-search with hashes?
Now I have a simple jquery search:
$(function(){
/// Start searching
$("form#search-form").submit(function(e){
var hash = 'q=' + encodeURI(document.getElementById('q').value);
window.location.hash = hash;
e.preventDefault();
$("#results").fadeOut();
$.ajax({
type:"GET",
data: $(this).serialize(),
url: "search.php",
success: function(msg){
$("#results").html(msg).fadeIn();
}
});
});
});
As you see, I have added here
var hash = 'q=' + encodeURI(document.getElementById('q').value);
window.location.hash = hash;
to have search-input in hash. So my idea is to type “http://url/#q=word” and have results for “word”. Currently my “hash function” is useless, it performs nothing – just adds value to address bar. How could I make jquery perform in that way?
I tried to add
if (window.location.hash != "") {
}
but it doesn’t help. Or I used to do that wrongly.
So.. may be it is too difficult, but it works:
In PHP: