harsh
harsh

Reputation: 131

jquery cookie not working

hey people i'm using a jquery plugin for creating cookies which seems to be working perfect when i run it on localhost but when I tested in the server it's not working as i expected.

below is my file testcookie.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<link rel="shortcut icon" href="3.ico">
<script type="text/javascript" src="js/iepngfix_tilebg.js"></script>
<script src="js/jquery-1.4.2.min.js"></script>
<script src="js/jquery.cookie.js"></script>
<script> 
(function($) {
$(document).ready(function() {

$.cookie("example", "foo");
alert( $.cookie("example") );

});})(jQuery);
</script>
</head>
<body>hello there</body>
</html>

result= no alert

here's the demo http://namadda.com/demo/testcookie.php

onething i noticed just now is that click view source and all the script link is working but jquery.cookie.js isn't showing up, instead i'm getting error 406 when i clicked jquery cooke link on view source page. But it's present on server like other plugins.

Upvotes: 2

Views: 10523

Answers (4)

hoangson
hoangson

Reputation: 31

Renaming the file jquery.cookie.js to something else should succeed.

Upvotes: 3

Sabir
Sabir

Reputation: 176

The best solution is renaming jquery.cookie.js file to something like jquery_cookie.js

It was the best solution for me, because I don't have permission to modify mod_security

Upvotes: 16

Dennis
Dennis

Reputation: 32598

When I visit http://namadda.com/demo/js/jquery.cookie.js I get a 406 Not Acceptable HTTP error.

An appropriate representation of the requested resource /demo/js/jquery.cookie.js could not be found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Something is not configured properly on your server.

Upvotes: 1

Rob W
Rob W

Reputation: 348962

  1. Make sure that the JQuery and js/jquery.cookie.js js files exist at the server.[1]
  2. Set the expiry date, so that the cookie doesn't get destroyed after the session.
  3. Set a path, so that your cookie is accessible from your whole site (optional).

Combining 2 and 3: $.cookie("example", "foo", {expires:7, path:"/"}) - Life time of 7 days

[1] A common novice mistake.

Upvotes: 5

Related Questions