Ajax request for autocomplete sends results back twice.

Ajax request for autocomplete sends results back twice.

I am sending a ajax request for search results and when I console.log() the results it sends the result back twice. Here is my code.

Any help would be appreciated. 
  1. //Ready the DOM
  2. $(function(){
  3. //Placeholder plugin for input text area
  4. $('input, textarea').placeholder();
  5. //bind a submit function to the form div
  6. $('form').bind('submit', function(e){ return false;});
  7. //variables for the input field, and search box div.
  8. var input = $('input').eq(0),
  9. search = $('#searchresults')
  10. ;
  11. //bind a keyup function to capture keystrokes
  12. input.bind('keyup', function(e){
  13. //variable that captures the values being put in the text field.
  14. var value = input.val();
  15. //fade in the search results box.
  16. search.fadeIn(500);
  17. //if statements for the up, down, esc, enter keystrokes.
  18. if(e.which === 38){ 
  19. }if(e.which === 40){
  20. }if(e.which === 13){
  21. search.find('li');
  22. }if(e.which === 27){
  23. search.fadeOut(500);
  24. //if statement that sends a ajax request when the keystrokes are 3 or more.
  25. }else if(value.length > 3){
  26. //the ajax request with options 
  27. $.ajax({
  28. url: 'xhr/vidsearch.php',
  29. type:'GET',
  30. dataType:'json',
  31. data:{q:$(this).val()},
  32. //success function with to show the results of the ajax request.
  33. success: function(response){
  34. //if statement to show a 'no result' response to input value that does not match ajax request.
  35. if(response.length) {
  36. $.each(response, function (i, item) {
  37. var listItem = $('<li><a href="'+ item.url+'"><img src="images/icons-small/'+ item.icon +'" /><span>'+item.title+'</span></a></li>')
  38. .appendTo(search);
  39. })
  40. }
  41.     }
  42.     
  43.         });
  44.  }
  45. return false
  46. });
  47. //binds a focusout function to the input field when the user click outside the search box the result box fades out.
  48. input.bind('focusout', function(e){
  49. search.fadeOut(500);
  50. });
  51. });