Reputation: 8424
trying to get my head around this problem:
I often load fragments of page via .load() function such as:
<div class="fragment_load">
<form>
<input id="typeaway" type="text" class="autocomplete"/>
<label>Test Type</label>
</form>
<script type="text/javascript">
$("#typeaway").autocomplete({
serviceUrl: "/restaway",
minChars: 3,
paramName: "query",
});
</script>
</div>
Now as you can imagine autocomplete is not working due to this.
I am unsure how to make it work going forwards for these small fragments that i load via AJAX.
Any assistance is appreciated.
Upvotes: 0
Views: 48
Reputation: 632
You can try below code:-
Just put it inside document.ready.
$(document).ready(function () {
$("#typeaway").autocomplete({
serviceUrl: "/restaway",
minChars: 3,
paramName: "query",
});
});
Upvotes: 0
Reputation: 337610
In this case you could put the autocomplete
initialisation code within the callback of the load()
method, something like this:
$('#foo').load('bar.html', function() {
$("#typeaway").autocomplete({
serviceUrl: "/restaway",
minChars: 3,
paramName: "query",
});
});
Upvotes: 1