加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ajax – 使用restful api进行简单搜索

发布时间:2020-12-16 02:47:18 所属栏目:百科 来源:网络整理
导读:我是一个完整的菜鸟尝试Ajax和 Jquery.通过在线教程,我成功地使用MySQL作为后端数据库创建了一个搜索引擎; script$(function() {$(".search_butn").click(function() { // getting the value that user typed var searchString = $("#input_box").val(); //
我是一个完整的菜鸟尝试Ajax和 Jquery.通过在线教程,我成功地使用MySQL作为后端数据库创建了一个搜索引擎;

<script>
$(function() {
$(".search_butn").click(function() {
    // getting the value that user typed
    var searchString    = $("#input_box").val();
    // forming the queryString
    var data            = 'search='+ searchString;
    // if searchString is not empty
    if(searchString) {
        // ajax call
        $.ajax({
            type: "POST",url: "search.php",//server-side script to db (mysql)
            data: data,beforeSend: function(html) { // this happens before actual call
                $("#results").html('');
                $("#searchresults").show();
                $(".word").html(searchString);
           },success: function(html){ // this happens after we get results
                $("#results").show();
                $("#results").append(html);
          }
        });
    }
    return false;
 });
});
 </script>

<form method="post" action="search.php">
<div id="DIV">
    <input type="text" name="search" id="input_box" class='input_box'/>
    <input type="submit" value="Search" class="search_butn" />
</div>
</form><br/>

<div>
 <div id="searchresults"> </div>
 <ul id="results" class="update">
 </ul>
</div>

现在我想进一步搜索使用像Solr这样的RESTful api http:// localhost:9090 / solr / select?q = employee:(james blunt)& wt = json& indent = true
我需要有人请告诉我如何才能做到这一点.

解决方法

要创建RESTful API,您可以编写一些PHP代码来删除请求的URL.
你应该让Apache – 我想你的网络服务器 – 将具有特定前缀的所有URL重定向到这个PHP脚本.

因此,如果用户请求http://www.somename.com/my_api/some/shiny?suffix,您希望Apache将此URL重定向到脚本my_api.php,这样my_api.php可以删除整个URL和做的事基于此.
对于Apache这样做,请阅读apache mod_rewrite:http://httpd.apache.org/docs/current/mod/mod_rewrite.html

有关RESTful API的更详细的处理,我可以建议本教程:http://www.restapitutorial.com/

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读