在cakephp中自动完成搜索

时间:2018-02-16 07:58:17

标签: javascript php json autocomplete

$( "#skills" ).autocomplete({source: function(request, response) {
    $.getJSON("http://server/current/indrealestates.com/properties/autosuggesthome/",{ term:request.term ,extraParams:$('#property_id').val()}, 
    response
        );
    },
    minLength: 2,
    focus:function(event, ui){$("#skills").val(ui.item.label);return false},
    select: function(event, ui){
        $("#skills").val(ui.item.label);$("#project-id").val(ui.item.value);
        window.location.href=ui.item.value+"/";
        return false
    }
});

我想在响应null时添加也没有找到显示的结果。当前此代码运行但未找到结果不显示请建议如何改进此代码

1 个答案:

答案 0 :(得分:0)

只需检查getJSON&中的响应是否为空。添加消息。

<强> e.g

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Shalom Kang Kong</title>
    <link rel="stylesheet" href="css/materialize.min.css">
    <link rel="stylesheet" href="stylesheets/style.css">
</head>
<body>