I am trying to combine ajax request with an autocomplete function. But it seems something is wrong for the autocomplete. I am using this to implement my code.
The console gives me back something like : http://domain.com/[%22...array from ajax here]?term=What i put in my input pointing a 403 error -.-
I am a bit lost though it seemed simple to me.
<script type='text/javascript'>
$("input[name=search]").on('keyup', function(){
jQuery.ajax({
type: 'POST', // Le type de ma requete
<?php echo "url: '".PTC.ROOT.DS."ajax'"; ?>, // URL to call (works)
data: {
search: ''+$("input[name=search]").val()+''
},
success: function(data, textStatus, jqXHR) {
window.availableNames = data; //JSON format
$(function() {
alert(window.availableNames); //Show the JSON encoded table with the right result.
$("input[name=search]").autocomplete({source: window.availableNames}); // Fails.
});
},
error: function(jqXHR, textStatus, errorThrown) {
}
});
});
</script>
Thank you
EDIT : Separately Ajax works, and Autocomplete works. But when I try to incorporate the second in the first, it doest.
Autocomplete has the option to provide an url as the source-parameter
So make sure the api endpoint located at the supplied url returns json and reacts correctly to the ‘term’ parameter.
This way you don’t have to fiddle with your own ajax calls.
So you autocomplete code would look something like this: