Php 服务器端-首次加载时bootsrap typeahead内部错误-未找到laravel http错误
我试图在表单中使用twitter引导程序typeahead,并使用服务器端查询从数据库中获取记录。 我已经启动并运行了该功能,一旦我开始输入3个字符后的搜索,它就会获取数据,这很好。 但是,在第一次加载页面时,我从主bootstrap-typeahead.js脚本中得到一个500错误异常,即:Php 服务器端-首次加载时bootsrap typeahead内部错误-未找到laravel http错误,php,laravel,bootstrap-typeahead,Php,Laravel,Bootstrap Typeahead,我试图在表单中使用twitter引导程序typeahead,并使用服务器端查询从数据库中获取记录。 我已经启动并运行了该功能,一旦我开始输入3个字符后的搜索,它就会获取数据,这很好。 但是,在第一次加载页面时,我从主bootstrap-typeahead.js脚本中得到一个500错误异常,即: NotFoundHttpException 我在使用页面时没有收到错误-只是在第一次加载时 因此,我假设脚本在服务器端使用一个空白查询对查询进行初始调用,这可能是原因。我尝试在laravel上的rout
NotFoundHttpException
我在使用页面时没有收到错误-只是在第一次加载时
因此,我假设脚本在服务器端使用一个空白查询对查询进行初始调用,这可能是原因。我尝试在laravel上的route和search函数中输入默认值,但仍然存在错误
页面按原样工作,但我不希望出现此错误。我从哪里开始找?我甚至不确定脚本是否提出了抛出错误的请求
下面是脚本-初始化typeahed函数:
$('#typeahead').typeahead({
source: function(query, process) {
if(query===null) {
query = 'aaa';
}
$.ajax({
url: '/customers/typeahead/'+query,
type: 'GET',
dataType: 'json',
//data: "query=" + query,
async: false,
success: function(data) {
customers = [];
map = {};
$.each(data, function(i, customer) {
//map object with unique name for each returned customer
map[customer.first_name + ' ' + customer.last_name + ': ' + customer.email + ' - ' + customer.id ] = customer;
customers.push(customer.first_name + ' ' + customer.last_name + ': ' + customer.email + ' - ' + customer.id);
});
process(customers);
}
});
},
minLength: 3,
updater: function(item) {
alert("selected");
id = map[item].id;
fetchCustomer(id);
return item;
}
});
static public function customerTypeahead($qry) {
//$qry = Input::get('query');
$qry='%'.$qry.'%';
$customers=Customer::where('first_name','like',$qry)
->orWhere('last_name','like',$qry)
->orWhere('email','like',$qry)
->get(array('first_name','last_name','email','id'))->toJson();
return $customers;
}
这是拉威尔的路线:
Route::get('customers/typeahead/{qry?}', function ($qry = 'a') {
return Customer::customerTypeahead($qry);
});
以下是laravel模型函数:
$('#typeahead').typeahead({
source: function(query, process) {
if(query===null) {
query = 'aaa';
}
$.ajax({
url: '/customers/typeahead/'+query,
type: 'GET',
dataType: 'json',
//data: "query=" + query,
async: false,
success: function(data) {
customers = [];
map = {};
$.each(data, function(i, customer) {
//map object with unique name for each returned customer
map[customer.first_name + ' ' + customer.last_name + ': ' + customer.email + ' - ' + customer.id ] = customer;
customers.push(customer.first_name + ' ' + customer.last_name + ': ' + customer.email + ' - ' + customer.id);
});
process(customers);
}
});
},
minLength: 3,
updater: function(item) {
alert("selected");
id = map[item].id;
fetchCustomer(id);
return item;
}
});
static public function customerTypeahead($qry) {
//$qry = Input::get('query');
$qry='%'.$qry.'%';
$customers=Customer::where('first_name','like',$qry)
->orWhere('last_name','like',$qry)
->orWhere('email','like',$qry)
->get(array('first_name','last_name','email','id'))->toJson();
return $customers;
}
你知道什么会引发初始错误以及如何开始跟踪吗
谢谢尝试将完整的网站url添加到jQuery的url对象。如果您想要动态url,您可以添加
<script>var WEBSITE_URL = {{ URL::to('/') }};</script>
尝试使用firebug查看发送的内容和返回的内容,以便更好地定位错误的位置 我添加了附加代码,但错误仍然存在。我将试着在小提琴中设置,看看是否可以复制。非常感谢。