Topic: Modify xajax to set cookie

xajax.js


this.createCookie=function(name,value,days){if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires="; expires="+date.toGMTString();}else var expires="";document.cookie=name+"="+value+expires+"; path=/";}   
this.readCookie=function(name){var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' ')c=c.substring(1,c.length);if(c.indexOf(nameEQ)==0) return c.substring(nameEQ.length,c.length);} return null;}
this.eraseCookie=function(name){this.createCookie(name,"",-1);}


xajaxResponse.inc.php
    function setCookie($cname,$cval,$cexp)
    {
        $this->xml .= $this->_cmdXML(array("n"=>"sc","t"=>$cname,"p"=>$cexp),$cval);
    }
   
    // eraseCookie($cname)
    function eraseCookie($cname)
    {
        $this->xml .= $this->_cmdXML(array("n"=>"ec"),$cname);
    }

Re: Modify xajax to set cookie

erm, I can't see any benefit from setting the cookie via JavaScript. setcookie works fine...

Re: Modify xajax to set cookie

Could it be useful when we want to set a cookie on the client from a field which is not created as part of a form, nor part of a call which is to be communicated back to the server :
xajax_something( $too, $many, $vars, $already)

I was going to do this as a "setting" or "state" set up on the client, which is picked up on the server with $_COOKIE ?

So you might have a checkbox say: "[ x ] display postal codes " that dictated whether that info should be displayed from now on.  Nothing needs to be sent server side just yet ...

Maybe there is another way of doing this, as a serious noob, I would guess that there probably is - but setting a cookie is something I am just about to write client side now - for the above reasons.

So ( in my igonorance, as I have pointed out already )  I'd agree with the OP.  some generic cookie setting code might be a nice idea.