1

I just started a new project File > ASP.NET MVC 4 Web Application > Internet Application

The problem i have is when I run the project it throws an error Uncaught TypeError: Object [object Object] has no method 'splitter' I know what the error means but the plugin file for the SPLITTER is loaded correctly.

I then started the project in a folder without the aid of Visual Studio - same file stucture, same code, everything works as expected.

  <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="splitter.js"></script>
    <script type="text/javascript">
        $(function () {
             $(".panel").splitter();
         });

     </script>

Am I missing something?

Simo Mafuxwana
  • 3,702
  • 6
  • 41
  • 59
  • @Cybermaxs-Betclic Its not a 404, on **Visual Studio** it can't find the method within splitter.js – Simo Mafuxwana Jul 11 '13 at 09:30
  • Visual Studio doesn't load anything. Your browser does. The difference is that Visual Studio starts the browser in a debugging mode, which the browser is not doing when you start it without it. The error still occurs, you just don't see it. Check the JavaScript console to see. – Erik Funkenbusch Jul 11 '13 at 19:22
  • @MystereMan CONSOLE? MMM WOW HOW COME I DIDN'T THINK OF THAT - Einstein! :/ – Simo Mafuxwana Jul 12 '13 at 11:53

3 Answers3

0

Hey try to call all your script in your "_Layout.cshtml" under the Folder Shared and add your scripts to Folder "Scripts"

then say somethink like that in _Layout.cshtml:

<script src="@Url.Content("~/Scripts/splitter.js")" type="text/javascript"></script>


so in all your views the script is loaded and should be correct loaded!

UPDATE:
in your view try :

$(document).ready(function () {
    $(".panel").splitter();
    window.splitter();         <------ try
});
0

IF the error is in Visual Studio, you need to add the splitter.js file to the _references.js file. This is how VS knows which Js files to check.

What is the _references.js used for?

Community
  • 1
  • 1
David Colwell
  • 2,450
  • 20
  • 31
0

Okay, the issue was $().ready(function () {... when working with a couple of jQuery plugins some use $ as something else (i.e: variable or instance of something) now when It gets to

<script type="text/javascript">
   $(function () {
        $(".panel").splitter();
    });
</script>

somehow $ is not at its native jQuery state. So to make sure I use it as I know it (the native jQuery way) It has to be passed to the function, like so...

jQuery(function ($) {...

So Visual Studio was not the issue :)

(My terminology is a bit rusty, feel free to edit so it can make sense)

Simo Mafuxwana
  • 3,702
  • 6
  • 41
  • 59