This function is called on onkeydown of textbox
function autoComplete(type, select) {
$('#search_name').autocomplete({
source: function( request, response ) {
$.ajax({
url: "/searches/autoComplete",
dataType: "json",
data: {
term: $.trim(request.term)
},
success: function( data ) {
response( $.map( data, function( item ) {
return {
label: item.value,
value: item.value,
type : item.type,
id : item.id
}
}));
}
});
},
minLength: 2,
select: function( event, ui ) {
var url = ui.item.type + '/edit/' + ui.item.id;
$(location).attr('href', url);
}
});
}
When checked in console gets an error as below
a is null
..."resolve"],fail:[b,"reject"],progress:[c,"notify"]},function(a,b){var c=b[0],e=b...
This error will comes only when no response data is returned, otherwise it is working fine.
How to avoid this error?
If you are expecting a request to return data, but it’s returning null, then that should not be treated as a success but as a failure. In your server code you should return 404 or something like that if you can’t return the requested data.
Edit: From comments below, seems this was best solved using
header("HTTP/1.0 404 Not Found");in PHP.I guess you could also just check in the JavaScript to avoid the error, but that isn’t really a clean solution..