$.autocomplete ajax test
by nareshreddye904
HTML
<script src="https://rawgit.com/appendto/jquery-mockjax/master/jquery.mockjax.js"></script>
<script src="https://code.jquery.com/ui/1.11.2/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.2/themes/black-tie/jquery-ui.css">
<input id="f" />
JavaScript
$('#f').autocomplete({
delay: 300,
source: function(request, response) {
$.get('http://localhost/test.php', {
q: request.term
}).success(function(availableTags) {
response(availableTags);
});
}
});
$.mockjax({
url: 'http://localhost/test.php',
response: function(settings) {
var availableTags = [
'a' + settings.data.q,
'b' + settings.data.q,
'c' + settings.data.q
];
this.responseText = availableTags;
}
});