dongmao9217 2017-01-16 23:40 采纳率: 100%
浏览 52
已采纳

让Google Site Search与我的网站合作

I have a website at. If you try to use the search box it gives a server error. For some reason it is not connecting properly to the Google Site Search and will not bring the results to the page. It at least took me to the search results page before I uploaded it to the server but after it just gives an error. I am new to setting this Google Site Search up on my own and I don't understand what I am missing to get this working.

search.html:

<div id="cse" style="width: 100%;">Loading</div>

<script src="http://www.google.com/jsapi" type="text/javascript"> </script>
<script type="text/javascript">

  google.load('search', '1');
 google.setOnLoadCallback(function(){
  var customSearchControl = new       google.search.CustomSearchControl('xxxxxxxxxxxxxxxxxxx');
  customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
  customSearchControl.draw('cse');
$(".gsc-input").val("<?php echo $_POST['q']; ?>");//insert into  search field requested search text
$(".gsc-search-button").click();//call button click event, show   results
}, true);
</script>
<link rel="stylesheet" href="http://www.google.com/cse/style/look/default.css" type="text/css" />

Search Box Code from index.html or homepage:

 <form class="navbar-form navbar-right" action="search.html" method="post">
    <div class="form-group">
      <input type="text" name="q" class="form-control" placeholder="Search...">
    </div>
    <button type="submit" name="search" value="Search" class="btn btn-default">Submit</button>
  </form>

Error Code on live site after search and submit:

Server Error

405 - HTTP verb used to access this page is not allowed. The page you are looking for cannot be displayed because an invalid method (HTTP verb) was used to attempt access.

Console Error:

Failed to load resource: the server responded with a status of 405 (Method Not Allowed)

New console errors after connecting with method="get" properly:

enter image description here

  • 写回答

1条回答 默认 最新

  • duanlie2709 2017-01-17 03:59
    关注

    I fixed this just by changing my search.html to search.php and then loading it back up onto the server. Makes sense it was something that simple. Code is below, thanks to all who helped me out.

    <form class="navbar-form navbar-right" action="search.php" method="get">
        <div class="form-group">
          <input type="text" name="q" class="form-control" placeholder="Search...">
        </div>
        <button type="submit" name="search" value="Search" class="btn btn-default">Submit</button>
    </form>
    
    <script type="text/javascript">
    
     google.load('jquery', '1');
     google.load('search', '1');
     google.setOnLoadCallback(function(){
     var customSearchControl = new google.search.CustomSearchControl('your-ID-here');
     customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
    customSearchControl.draw('cse');
    $(".gsc-input").val("<?php echo $_GET['q']; ?>");//insert into search field requested search text
    $(".gsc-search-button").click();//call button click event, show  results
    }, true);
    
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)