0

I am developing w php web site. Here I have set a php cookie

 setcookie('hotelId',$resHotel); 

I want to check whether it’s set or not using jquery or javascript. I have used the following code

if($.cookie('hotelId')) {
        alert("yes");
    };

But it's not working

Is there is any way to find PHP cookie is exist or not in jquery

Thanks

user1263260
  • 243
  • 3
  • 6
  • 17
  • related : [stackoverflow.com/questions/1599287/...](http://stackoverflow.com/questions/1599287/create-read-and-erase-cookies-with-jquery) – safarov Mar 30 '12 at 08:47
  • No, My question is " How to check a 'php' cookie is exist or not using jquery ". I don't have the jquery cookie, i have php cookie – user1263260 Mar 30 '12 at 08:51

3 Answers3

0

That should work if these two conditions are met:

  • you have installed the extra library that you need to use $.cookie()
  • you have called setcookie() before outputting any part of your html
Nicola Peluchetti
  • 76,206
  • 31
  • 145
  • 192
0

Are you sure that you have the right libraries loaded into the page? I don't think cookie behavior is included with jQuery by default.

You can view cookies manually easily. The method varies a little from browser to browser, but (in Firefox, for example) if you go to Preferences > Privacy > remove individual cookies, you can browse through them and see their contents. This can help you debug whether your php code is setting the cookie as desired.

Cameron
  • 1,675
  • 11
  • 12
0

First get the specified cookie as follows

var cookie=$.cookie("set");
if(!cookie)
{
   $.cookie("set","foo"); //if there is no cookie set it
}
Manigandan Arjunan
  • 2,260
  • 1
  • 25
  • 42