Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ajax 使用restfulapi进行简单搜索_Ajax_Rest_Solr_Search Engine - Fatal编程技术网

Ajax 使用restfulapi进行简单搜索

Ajax 使用restfulapi进行简单搜索,ajax,rest,solr,search-engine,Ajax,Rest,Solr,Search Engine,我完全是个傻瓜,正在尝试Ajax和Jquery。通过在线教程,我成功地制作了一个以MySQL为后台数据库的搜索引擎 <script> $(function() { $(".search_butn").click(function() { // getting the value that user typed var searchString = $("#input_box").val(); // forming the queryString

我完全是个傻瓜,正在尝试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>

$(函数(){
$(“.search_butn”)。单击(函数(){
//获取用户键入的值
var searchString=$(“#输入框”).val();
//形成查询串
变量数据='搜索='+搜索字符串;
//如果searchString不是空的
如果(搜索字符串){
//ajax调用
$.ajax({
类型:“POST”,
url:“search.php”,//数据库的服务器端脚本(mysql)
数据:数据,
beforeSend:function(html){//这发生在实际调用之前
$(“#结果”).html(“”);
$(“#搜索结果”).show();
$(“.word”).html(搜索字符串);
},
success:function(html){//这在我们得到结果之后发生
$(“#结果”).show();
$(“#结果”).append(html);
}
});
}
返回false;
});
});

现在我想更进一步,使用一个RESTful api进行搜索,就像Solr
http://localhost:9090/solr/select?q=employee%3A%28james+blunt%29&wt=json&indent=true

我需要有人告诉我怎么做

要创建RESTful API,您可以编写一些PHP代码来切碎请求的url。 您应该让Apache(我想是您的Web服务器)将带有特定前缀的所有URL重定向到此PHP脚本

因此,假设用户请求
http://www.somename.com/my_api/some/shiny?suffix
,您希望Apache将此URL重定向到脚本
my_api.php
,这样
my_api.php
就可以删除整个URL并基于此执行操作。 对于Apache,请阅读Apache mod_rewrite:

对于RESTful API的更详细的处理,我建议使用本教程: