jQuery Autocomplete Not Working

Leave a Comment
When you are integrating jquery autocomplete, please ensure following things if jquery autcomplete is not working.

1. Please ensure following css and js files are added in your script file.
<link rel="stylesheet" href="css/jquery-ui-1.10.3.custom.min.css" />
<script src="js/jquery-1.10.2.min.js"></script> 
<script src="js/jquery-ui-1.10.3.custom.min.js"></script>
2. jQuery autocomplete expects json formatted array as response. So please ensure that your are sending the right formatted response to jQuery autocomplete.
$('#country_name').autocomplete({
 source : function(request, response) {
  $.ajax({
   url : 'ajax.php',
   dataType : "json",
   data : {
    name_startsWith : request.term,
    type : 'country'
   },
   success : function(data) {
    response($.map(data, function(item) {
     return {
      label : item,
      value : item
     }
    }));
   }
  });
 },
 autoFocus : true,
 minLength : 0
});
Ensure that dataType json is mentioned as well as right url are given. If you still have implementing this jQuery autocomplete, Please refer following two tutorials.



0 comments:

Post a Comment