1

I want to load another page via Javascript like this

$("#resultarea").load("searchresults.php?searchstring=" + $("#searchbox").val());

in searchresults.php, a single statement

echo $_GET["searchstring"];

what I type in searchbox appears when searchresults.php is loaded except when I add space and another word, no thing appear at all. I heared it can be done by encoding or somewhat, I searched but didn't find a solution.

1
  • As you are using jQuery, you can probably do .load('searchresults.php', {'searchstring': $("#searchbox").val()}); Commented May 16, 2014 at 0:13

1 Answer 1

3

Try encodeURIComponent:

var encodedValue = encodeURIComponent($("#searchbox").val());
$("#resultarea").load("searchresults.php?searchstring=" + encodedValue);

Source

Demo

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.