php - Javascript encodeURIComponent issue on redirection -


i've search box works jquery , php, when type in search box jquery prepares query , redirects location. preparing query part works redirection part has problem encoded query. page automatically decodes encoded query before redirection.

if type "test1 test2 test3" in search box, encodes query test1%20test2%20test3 encodeuricomponent().

now page redirect result.php+query. problem here page goes result.php?q=test1 test2 test3 instead of result.php?q=test1%20test2%20test3.

here codes

 if($("#searchbox").val() != "")  {     var mq1 = encodeuricomponent($("#searchbox").val());     var query = "q="+mq1;   }   alert(query);  if(query!="")  location = "result.php?"+query; 

alert result q=test1%20test2%20test3 goes result.php?q=test1 test2 test3

edit: if use encodeuricomponent function redirection codes works good.

 alert(query);  if(query!="")  location = "result.php?"+encodeuricomponentquery); 

theese codes working encodes q= part too.

since you're using jquery, why not write this:

if ($("#searchbox").val()) {     location = 'result.php?' + $.param({         q: $("#searchbox").val()     }); } 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -