3

Chrome on Rails on Localhost. Here's a trimmed version of the page:

<!DOCTYPE html>
<head>
  <link href='http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css' rel='stylesheet'>
  <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js' type='text/javascript'></script>
  <script src='http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.js' type='text/javascript'></script>
  <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.3.1/jquery.cookie.min.js' type='text/javascript'></script>
  <meta content="authenticity_token" name="csrf-param" />
  <meta content="blahblah=" name="csrf-token" />
  <link href="/assets/application.css?body=1" media="all" rel="stylesheet" type="text/css" />
  <script src="/assets/application.js?body=1" type="text/javascript"></script>
  <meta name="viewport" content="width=device-width, initial-scale=1.0 maximum-scale=1.0">
</head>
<body data-action='index' data-controller='application'>
</body>

In the Chrome console (and in scripts farther down), $.cookie is undefined and $.cookie("a", "b") throws an error.

I've tried a few other CDNs, but same issue.

Edit: I'm trying things out in the Chrome Javascript console, which (I presume) runs after page load. I can check the "Resources" tab and see that the plugin has been loaded without issue. If I rearrange to link the plugin prior to Jquery, I get expected errors.

Narfanator
  • 5,595
  • 3
  • 39
  • 71
  • 1
    Make sure that you do it after the JavaScript has been loaded (document ready): http://jsfiddle.net/cq9m8/ – pickypg May 02 '13 at 02:42
  • 1
    Are you using `http://localhost` or `file://localhost`? Since your URLs don't have an "http:" prefix, they inherit the protocol used for the containing page. – Barmar May 02 '13 at 02:45
  • 1
    Provide the code snippet / block that contains $.cookie – Ryan Gibbons May 02 '13 at 02:45
  • In the Chrome Javascript console: `$.cookie("a", "b")` – Narfanator May 02 '13 at 02:47
  • Barmar: Not specifying, but usually HTTP. I changed the src addresses to specify the protocol, but no go. – Narfanator May 02 '13 at 02:48
  • What does `$.fn.jquery` give you? (to confirm something isn't overwriting `$`) – Kevin B May 02 '13 at 02:59
  • 2
    JavaScript cookies don't work in Chrome on `localhost`. Not sure if that could relate to this or not. http://stackoverflow.com/questions/335244/why-does-chrome-ignore-local-jquery-cookies – matthewpavkov May 02 '13 at 03:02
  • 1
    try using `http://127.0.0.1` instead – MikeM May 02 '13 at 03:11
  • 1
    @matthewpavkov Chrome accepts cookies from a web server on localhost but not when the page is served as a local file. OP: Could you provide the code from application.js? – Rob K May 02 '13 at 03:15
  • Purely the generated file; comments comments `//require_tree .` – Narfanator May 02 '13 at 18:44

1 Answers1

1

I checked the javascript files served by my application via the "resources" tab, and discovered that my application.js still had JQuery in it, so, presumably, it was redefining the JQuery without Coookie when the file was loaded.

This occurred because I switched from using gems to load JQuery to using an external CDN, but did not recompile (or delete) my assets.

Solved by removing the compiled assets from public/assets

Narfanator
  • 5,595
  • 3
  • 39
  • 71