Jump to content

change a line of php into jQuery...


JKG

Recommended Posts

hi, i have this line of PHP

 

<?php if(strstr($_COOKIE['contact_ids'], $row['ID']) !== FALSE){echo 'checked';}?>

 

it works fine, but needs a page reload to show the changes.

 

does anyone know how i can achieve this effect in jQuery? particularly the strstr() function. thanks again!

Link to comment
https://forums.phpfreaks.com/topic/246137-change-a-line-of-php-into-jquery/
Share on other sites

That's because PHP doesn't actually create a cookie. When you set it, PHP adds a header to the response it sends back to the browser at the end of execution. When the browser receives this header it then creates the cookie, so effectively you have to wait until the next request. What you can do, is at the point of creating the cookie, manually add it to the $_COOKIE array:

 

setcookie(...);
$_COOKIE['...'] = '...';

Yep that makes perfect sense - I thought you were talking about a different problem. jQuery doesn't have native support for cookies (though there are plug-ins). Vanilla JS isn't that easy to work with them either. Instead of a nice clean array like in PHP, you have a string with the cookies separated by a semi-colon, which you access through document.cookie. Which route would you like to take?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.