0

I have an issue with a site i run that when cookies are disabled completely user cannot continue through a booking process.

I use Jquery and the cookie plugin, the cookie appears to always return [object Object] when cookies are disabled. Code for checking this is:

alert($.cookie("sourceID")); //returns [object Object]
if($.cookie("sourceID") === null || $.cookie("sourceID")=== '[object Object]'){
sourceID = 27201;
}else{
sourceID = $.cookie("sourceID");
}
alert(sourceID);  //returns [object Object]

the above is trying to set a default sourceID if the user does not have cookies enabled. This is then passed (along with other information) into another function that builds XML and passes it to a server for handling; however due to the [object Object] issue when this is passed the server cannot find a sourceid that matches.

Arazmus
  • 37
  • 1
  • 2
  • 7
  • There is no such thing as "the" jQuery cookie plugin...do you mean https://github.com/carhartl/jquery-cookie ? – JAAulde Aug 12 '11 at 19:22
  • yes that is the one; however according to http://plugins.jquery.com/project/Cookie it is a plugin – Arazmus Aug 16 '11 at 16:48
  • I know it is _a_ plugin, I am saying there is no such thing as _the_ jQuery cookie plugin. That said, the only thing that makes it a plugin is that it resides under the jQuery namepsace--for which there is no reason. It neither provides jQuery-like functionality nor uses any jQuery functionality. Very odd. – JAAulde Aug 16 '11 at 17:32
  • ah i see what you mean, agreed it doesn't really need to be a plugin as its not really providing any extra Jquery functionality.. but it does the job i need it to.. – Arazmus Aug 18 '11 at 09:42

1 Answers1

0

i found a work around for this issue, as i was trying to retrieve an integer value from the cookie it was possible to check to see if the value of the cookie returned was numeric. To do this i use the answer from this question: Validate decimal numbers in JavaScript - IsNumeric() and used:

if(isNumeric($.cookie("sourceID"))){
sourceid = $.cookie("sourceID");
}else{
sourceid = 27201;
}

not the best way to check that the cookie is returning a valid value but i would suggest anyone that hits this issue in the future to validate against what they know the cookie should contain (int, specific string etc)

Community
  • 1
  • 1
Arazmus
  • 37
  • 1
  • 2
  • 7