我特指jQuery Autocomplete v1.1插件JörnZaefferer [来源:
http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/],因为这个插件似乎有很多变体。
我试图传递额外的参数到服务器,当用户开始输入,因为我有多个字段,我想自动完成提供建议。
除了查询,我想发送输入名称属性到服务器,但我似乎不能在extraParams中使用$(this).attr(‘name’)。
我的jQuery:
$('.ajax-auto input').autocomplete('search.php',{ extraParams: { search_type: function(){ return $(this).attr('name'); } } })
这是我的HTML。
<form method="post" action="#" id="update-form" autocomplete="off"> <ol> <li class="ajax-auto"> <label for="form-initials">Initials</label> <input type="text" id="form-initials" name="initials" /> </li> <li class="ajax-auto"> <label for="form-company">Company</label> <input type="text" id="form-company" name="company" /> </li> </ol> </form>
有什么建议么?
解决方法
我使用自动完成功能,现在是jquery ui的一部分。
传递“extraParams”字段不起作用,但您可以在请求查询字符串中附加值。
传递“extraParams”字段不起作用,但您可以在请求查询字符串中附加值。
$(document).ready(function() { src = 'http://domain.com/index.php'; // Load the cities straight from the server,passing the country as an extra param $("#city_id").autocomplete({ source: function(request,response) { $.ajax({ url: src,dataType: "json",data: { term : request.term,country_id : $("#country_id").val() },success: function(data) { response(data); } }); },min_length: 3,delay: 300 }); });
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。