Many developers have been caught up by this error message judging by the number of posts on StackOveflow! I had to spend a few hours with this exception until finding the solution. Now I know that writing code while tired is never a good thing!
Object [object Object] has no method..
This error, in most cases, means that jQuery is not working and no such function can be found or is supported.
At first I thought that it was the bundling of the jQuery files that wasn’t working as expected so I removed the bundles from the page and the _layout.cshtml (master layout page in MVC) and I hardcoded the references to the necessary .js and .css file on the page in question but the problem persisted.
After a quick break I returned to my desk with renewed energy to fight this problem! I loaded the page and looked at the code behind in Dev Tools. Lo and behold the error at the bottom of the page:
... previous page code omitted <section> <div> <footer> <div class="content-wrapper"> <div class="float-left"> <p>&copy; 2013 - My ASP.NET MVC Application<p> <div> <div> <footer> <script src="/Scripts/jquery-1.7.1.js"><script> </div> <body>
In MVC 4, the
_layout.cshtml page puts the jQuery reference in the footer! Since I didn't notice, I ended up adding it twice to my page and when this happens the browser just refuses to work with jQuery. So if you see this error message again and your issue doesn’t fall into the other categories mentioned above, check for duplicate references to your js files!
- Ensure that there is no typos or syntax errors in your scripts
- Ensure that the “<script>” tag is closed correctly using </script> and not the /> self-closing format