How to set and read cookie value using Java
<p>I am working on a mobile app, I build it using HTML 5, Ajax, jQuery and CSS. <br>
I wrote the following codes to store loged-in user ID and name;<br></p>

<pre><code>&lt;script&gt;
    document.cookie = "id="+"1";
    document.cookie = "name="+"Demo Name";
&lt;/script&gt;
</code></pre>

<p>I have also written this function to read value of a cookie using its name;</p>

<pre><code>function readCookie(name) {
    name += '=';
    for (var ca = document.cookie.split(/;\s*/), i = ca.length - 1; i &gt;= 0; i--)
        if (!ca[i].indexOf(name))
            return ca[i].replace(name, '');
}
</code></pre>

<p>I call the following to read the name of the logged-in user into a variable called name;</p>

<pre><code>var name = readCookie('name'); 
</code></pre>

<p>The codes above works fine while testing on a web browser but when i try to run it in the mobile app (compiled with Phonegap), the var name returns "undefined", which means that the script was not able to read the cookie value..<br><br>
Please can anyone help me out here!<br><br>
I cant figure out what i did or if am missing something.<br><br>
I need to use cookie to validate logged in user in my mobile app.<br><br>Thanks</p>