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

2

3 Answers 3

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
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.

0

First get the specified cookie as follows

var cookie=$.cookie("set");
if(!cookie)
{
   $.cookie("set","foo"); //if there is no cookie set it
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.