I’ve a search box works with jquery and php, when you type something in to this search box jquery prepares a query and redirects location. Preparing query part works good but redirection part has a problem with the encoded query. Page automatically decodes the encoded query before redirection.
If you type “test1 test2 test3” in to search box, it successfully encodes query to test1%20test2%20test3 with encodeURIComponent().
Now page will redirect itself to result.php+query. My problem here is page goes to result.php?q=test1 test2 test3 instead of result.php?q=test1%20test2%20test3.
here are codes
if($("#searchbox").val() != "")
{
var mq1 = encodeURIComponent($("#searchbox").val());
var query = "q="+mq1;
}
alert(query);
if(query!="")
location = "result.php?"+query;
alert result is q=test1%20test2%20test3 but it goes result.php?q=test1 test2 test3
edit: If i use encodeURIComponent function with redirection codes it works good.
alert(query);
if(query!="")
location = "result.php?"+encodeURIComponentquery);
theese codes are working but it encodes q= part too.
Since you’re using jQuery, why not just write this: