gpt4 book ai didi

javascript - PHP $_Get 和 JQuery .load

转载 作者:行者123 更新时间:2023-11-28 19:49:47 25 4
gpt4 key购买 nike

我想通过 JavaScript 加载另一个页面,如下所示

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

在searchresults.php中,一条语句

echo $_GET["searchstring"];

我在搜索框中输入的内容会在加载 searchresults.php 时出现,除非我添加空格和另一个单词,否则根本不会出现任何内容。我听说可以通过编码或其他方式来完成,我搜索了但没有找到解决方案。

最佳答案

尝试encodeURIComponent :

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

Source

Demo

关于javascript - PHP $_Get 和 JQuery .load,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23690600/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com