javascript - How to make ajax call and get results back while typing in input text -
i want implement functionality when enter text in
<input path="tags" id="input-search"/>
there should appear list of suggested tags
after making ajax call. have database query
public interface tagrepository extends jparepository<tag, integer> { @query("select t tag t name concat('%', :name, '%')") list<tag> findtagbyname(@param("name") string name); }
and controller code
@requestmapping(value = "/gettags", method = requestmethod.post, produces = "application/json") public @responsebody list<tag> gettags(@requestbody tag tag, httpservletresponse response) { system.out.println("found " + string.valueof(tagservice.findtagbyname(tag.getname()).size())); return tagservice.findtagbyname(tag.getname()); }
javascript ajax
$(document).ready(function() { $("#tag-search").autocomplete({ source: function(request, response) { $.ajax({ url: "/app/gettags/", type: "post", data: json.stringify({tag : request.term}), datatype: "json", success: function(data) { response($.map(data, function(v,i){ console.log(); return { label: v.empname, value: v.empname }; })); } }); } }); }); <div class="col-md-10 col-md-push-1"> <label class="floating-label" for="login-username">tags</label> <form:input path="tags" cssclass="form-control" id="tag-search"/> </div>
when run app see javascript error in developers tools
important
i'm using daemonite/material front-end & jquery-autocomplete, thing latest version of app on github can 1 tell me how can rid of that error response welcome.
check jquery vendor library loaded or not.
to cross check:
<script> if (window.jquery) { alert('jquery loaded'); } else { alert('jquery not loaded'); } </script>
Comments
Post a Comment