I've created a live search form in laravel
, using jQuery ajax
on keyup
. I'm using a datalist
to add the options
to the datalist
. My database has around 3000 records of all German cities and when the user starts typing in the datalist
, the ajax request
is sent to the server and all possible cities are returned to my page. This is my query:
我在laravel中创建了一个实时搜索表单,在keyup上使用jQuery ajax。我正在使用datalist将选项添加到datalist。我的数据库有大约3000个德国城市的记录,当用户开始输入数据列表时,ajax请求被发送到服务器,所有可能的城市都返回到我的页面。这是我的查询:
$cities = DB::table('cities')->where($city,'like',$request->search.'%')->pluck($city);
This is my jQuery ajax call:
这是我的jQuery ajax调用:
$.ajax({
type : 'get',
url : '/'+'en'+'/search',
data:{'search':search_value,country:country,'_token':token},
dataType:"json",
success:function(data){
$('#cities').empty();
var citylist='';
$.each(data, function (i, item) {
citylist+="<option value='" + item + "'>"
});
$('#cities').append(citylist);
}
});
This code works super fast on a normal browser on a computer
or laptop
but as soon as I try it on a mobile device
it hangs and doesn't response. I get all 200 code
back which means that the request
and response
was successful but when I type the first letter I have to wait a minute long to see the newly added options
and wait another minute for each newly entered letter. My connection is 4G super fast
. The same problem appears when I go to responsive mode
in my firefox
or chrome
browser in my pc
. I'm very confused about the problem and any help would be appreciated. Thanks in advance.
此代码在计算机或笔记本电脑上的普通浏览器上运行速度非常快,但只要我在移动设备上尝试它就会挂起并且不响应。我得到了所有200个代码,这意味着请求和响应成功但是当我输入第一个字母时,我必须等待一分钟才能看到新添加的选项并等待每一个新输入的字母再等一分钟。我的连接速度是4G超快。当我在我的电脑中的firefox或chrome浏览器中进入响应模式时,会出现同样的问题。我对这个问题非常困惑,任何帮助都会受到赞赏。提前致谢。
1 个解决方案
#1
-1
Try to add async: false
inside your ajax.
尝试在ajax中添加async:false。
#1
-1
Try to add async: false
inside your ajax.
尝试在ajax中添加async:false。