我正在尝试进行动态搜索。当用户在输入字段中输入字符时,结果将从模型中返回。我没有使用此代码返回结果:
//here is my HTLML:
<input type='text' placeholder='Search By Email' class='searchterm' >
//here is my jQuery:
$(".searchterm").keyup(function(e){
var q = $(".searchterm").val();
$.getJSON("searchpeeps",
{
q: q,
},
function(data) {
$("ul.peepList").empty();
$("ul.peepList").append(" Results for <b>" + q + "</b>");
$.each(data.query.search, function(i,item){
$("ul.peepList").append("<li>"++"</li>");
});
});
});
//here is my get route:
Route::get('searchpeeps/{q}', array('as' => 'searchpeeps', 'uses' => 'PeopleController@searchpeeps'));
//here is my controller:
public function searchpeeps($id)
{
$uid = Auth::user()->id;
//$q = Input::get('q');
return Invite::where('email', $id)
->where('user_id', $uid)
->orderBy("created_at", "desc")
->groupBy('email')
->get();
}
答案 0 :(得分:0)
您没有注册正确的网址。 解决这个问题的两种方法&amp;写了一些代码以便更好地理解(根据您的需要调整它)
<强> 1。调整PHP
// Here, modified URL
Route::get('searchpeeps', function(){
return Input::get('q');
});
使用此Javascript
$(".searchterm").keyup(function(e){
$.getJSON(
"searchpeeps",
{ q: this.value },
function(data) {
console.log(data);
}
);
});
<强> 2。调整Javascript
$(".searchterm").keyup(function(e){
$.getJSON(
"searchpeeps/" + this.value,
null,
function(data) {
console.log(data);
}
);
});
...用这个PHP
Route::get('searchpeeps/{q}', function($q){
return $q;
});