传递变量,谷歌自定义搜索引擎
-
21-09-2019 - |
题
是否可以搜索变量传递到谷歌自定义搜索引擎,我已经嵌入在我的网站?我可以得到搜索引擎的工作,但我不能将它传递通过POST(它是从网站的其他页面的搜索按钮来)
术语我试图破解我发现这里的代码: HTTP: //code.google.com/apis/ajax/playground/?exp=search#hello_world
这是我迄今为止...($ q是我传递给它的期限)
<script type="text/javascript">
google.load('search', '1', {language : 'en'});
function OnLoad()
{
var customSearchControl = new google.search.CustomSearchControl('***my key****');
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
customSearchControl.draw('cse');
searchControl.execute("$q");
}
google.setOnLoadCallback(OnLoad);
</script>
由于
解决方案
对不起,我知道这是一个糟糕的答案,但你实际上是从引用了错误的变量名这样做是正确分开。哦也,顺便说一句,我也希望你做某种禁制上$ Q,万一有人贴出这样的事情到您的窗体:术语“);警报(”啊哈
customSearchControl.draw('cse');
searchControl.execute("$q");
应该是:
customSearchControl.draw('cse');
customSearchControl.execute("$q");
此外,谢谢你的问题 - 我一直在寻找如何做到这一点我自己
!其他提示
这是使用PHP试图完成这个相同的目标帮助任何人。上述用途的例子...
customSearchControl.execute("$q");
读取参数是在传球。在一个PHP的网站,你会用......
customSearchControl.execute("<?php echo $_POST['your_paramter_name_here'];?>");
您可以,如果你的参数是不是在后使用$ _GET或$ _REQUEST。
当然,你应该应该首先净化输入。这样的事情是非常弱的,但它是一个开始......
customSearchControl.execute("<?php echo htmlentities( trim( $_POST['your_paramter_name_here'] ), ENT_QUOTES );?>");
在万一有人正在寻找一个位更直接的/简单的解决方案。所有您需要做的是搜索关键词传递到GET参数名为问:(从您的自定义表单到页面,您的GCS是),GCS会自动使用该搜索短语。
来源: https://developers.google.com/custom-搜索/ JSON-API / V1 / using_rest
不隶属于 StackOverflow