JQuery UI AutoComplete Code Issue with Function as Source
So essentially, I have tried to move to a function that does the work for the source
parameter in the autocomplete method, and now the script is broken. No options show up upon typing even though values are being returned by the $.get(...)
request.
The HTML:
<tr class="itemTableRow">
<td>
<input type="text" class="item" name="items[]" />
</td>
<td>
<input type="range" class="quantity" min="1" max="10000" name="quantity[]" />
</td>
<td>
<select class="versionSelect"><option value="5">5</option><option value="6">6</option><option value="7">7</option></select>
</td>
</tr>
The Javascript:
$(function() {
$( ".item" ).autocomplete({
source: function(request, response){var data = $.get("http://mydomain.com/dev/kohana/utils/items/search?searchType=maxList&term=" + request.term + "&version=" + $(".item").parent().parent().children(":nth-child(3)").children("select").val()); console.log("" + data); response(data);},
minLength: 2
});
});
The resulting HTTP GET Request URL (when CP is entered in input field):
http://mydomain.com/dev/kohana/utils/items/search?searchType=maxList&term=CP&version=5
The resulting HTTP Response Body:
[{"label":"CP1031L","value":"CP1031L"},{"label":"CP1031M", "value":"CP1031M"]
I also have included the Jquery UI default stylesheet on the page, although it was working before that. I feel like I am missing something very basic with how the functional callback is supposed to work. Can anybody spot the problem? Thank you for your assistance.
您应该在.get()
调用的成功处理程序上调用response(data)
,如下所示:
$( ".item" ).autocomplete({
source: function(request, response){var data = $.get("http://mydomain.com/dev/kohana/utils/items/search?searchType=maxList&term=" + request.term + "&version=" + $(".item").parent().parent().children(":nth-child(3)").children("select").val(), function(data) {response(data);});},
minLength: 2
});
链接地址: http://www.djcxy.com/p/65280.html
上一篇: 估计二维图像的分形维数