문제

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.

도움이 되었습니까?

해결책

Try encodeURIComponent:

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

Source

Demo

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top