【发布时间】:2012-02-02 23:24:06
【问题描述】:
我不确定为什么会发生这种情况,但是当我的页面加载时,搜索结果会立即出现 XHR 请求。它对用户是不可见的,但它正在加载相当大的 json 数据块。
这是我的代码:
$.ajax({
type: "POST",
url: "http://localhost:8888/index.php/ajax/get_client",
dataType: "json", data: "{}",
success: function(data) {
$('#search').autocomplete({
source:data,
minLength:2,
delay:0,
appendTo:'header',
selectFirst:true,
select:function(event, ui) {
$("input#search").val(ui.item.value);
$("#search").closest('form').submit();
}
});
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown);
}
});
我怎样才能做到只有当用户在 input#search 框中键入时才请求 json 数据?
【问题讨论】:
标签: php jquery ajax json codeigniter