Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught TypeError: Object [object Object] has no method 'autocomplete'

I am trying to use the jQuery autocomplete feature on an ASP MVC 3 web page. Unfortunately I keep getting this error. I've looked at version 1.9.2, which I'm using, and it does have the autocomplete method. I am, however, completely new to jQuery and not sure if there are too many declarations in the header, conflicting libraries, or missing ones.

Below is the code from the view

<link href="../../Content/jquery-ui-1.9.2.custom.css" rel="stylesheet">

<script src="http://code.jquery.com/jquery-1.8.3.js" type="text/javascript"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.tablesorter.min.js")" type="text/javascript"></script>

<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.js"></script>
<script type="text/javascript">

    $(document).ready( function() {
      $('#BankName').autocomplete('@Url.Action("GetBanks", "AgentTransmission")', {
          dataType: 'json',
          parse: function(data) {
              var rows = new Array();
              for(var i=0; i<data.length; i++){
                  rows[i] = { data:data[i], value:data[i].SignalName, result:data[i].SignalName };
              }
              return rows;
          },
          formatItem: function(row, i, n) {
              return row.SignalName + ' - ' + row.Description;
          },
          width: 300,
          mustMatch: true,
      });
    });

Full html can be found here: http://jsfiddle.net/qpvBv/

like image 936
NealR Avatar asked Apr 07 '13 02:04

NealR


1 Answers

You're using multiple versions of jQuery. Include only one and put it at the top of all the scripts.

Including multiple versions of jQuery does not work because:

  1. First you include jQuery 1.8.3. This is okay(ish).
  2. Then you include jQuery UI 1.9.2. This is also okay, although I'd probably make sure that the versions of jQuery and jQuery UI match up. jQuery UI 1.9.2 is installed on the 1.8.3 jQuery object.
  3. Then you include more plugins, also installed on the 1.8.3 jQuery object.
  4. Then you include jQuery 1.6.4. Apart from it being out of date, it overwrites the 1.8.3 jQuery object with its own 1.6.4 jQuery object, overwriting all the plugins on the old one with it.
like image 139
icktoofay Avatar answered Nov 04 '22 21:11

icktoofay