antman1p
antman1p

Reputation: 524

Why is JQuery not working in my MVC 4 application after Firefox Update?

I have been writing an ASP.NET MVC 4 project in VS. I had it working perfectly in an older version of Firefox and in IE 11. It still works great in IE 11, but after I updated FF to 35.0.1, My script is not working. How do I get my script to work in the newest version of Firefox?

My _Layout view contians the following script:

 ......
 @Scripts.Render("~bundles/jquery")
 <script>
      $.ajax({
      url: '@Url.Action("Action", "Controller")',
      type: 'post',
      cache: 'false,
      async: 'true',
      data: '{}',
      success: function(result){
      $('#progress').html(result);
           } 
      });

      $(document).ready(function(){
           function RefreshPartial(){
                setTimeout(function(){
                     loadPartialView();
                    RefreshPartial();
                }, 3000);
           }
      RefreshPartial();
      }); 
 </script>
 @RenderSection("scripts", required:  false)
 </body>
 ......

In Firefox/Fox It hits the

 "$(document).ready(function ()  {" 

line then jumps to the bottom of the script

 });

before going to the Jquery. It never comes back to my inline JS. It throws the following exception: "SyntaxError: An Invalid or illegal string was specified" at the "if" statment below:

 3093     for ( ; list && firingIndex < firingLength; firingIndex++ ) {
 3094          if ( list[ firingIndex ].apply{ data[  ], data[ 1 ] ) == false && options.stopOnFalse )  {
                    memory = false;
                    break;
               }
          }

It loops through the for statment several times and then throws an error at the same if statement: "TypeError: Constructor Document requires 'new'". It never runs my inline script so my partial view is never loaded. Again, this only happens in the newest version of FF.

Upvotes: 0

Views: 785

Answers (2)

ScarletMerlin
ScarletMerlin

Reputation: 475

I see not reason why it should not work... Have you try doing a simple jquery alert? does it work? remove the ajax call and do the alert if you get the alert to work, then your jquery is working. otherwise you might not been linking jquery properly. if the alert works try a simple hit or miss ajax call.

    $.ajax( "example.php" )
  .done(function() {
    alert( "success" );
  })
  .fail(function() {
    alert( "error" );
  })
  .always(function() {
    alert( "complete" );
  });

Edit: there is not reason why FF would not work with $(document).ready(function(){}); I am currently using it for a web service and it works just fine with: safari, chrome, FF and IE plus four or five more mobile browsers.

Upvotes: 0

antman1p
antman1p

Reputation: 524

Firefox 35.0.1 does not like th e long version of:

 $(document).ready(function(){

My code works using the shorthand version:

 $(function()  {

I don't know why, but it worked right away.

Upvotes: 1

Related Questions