I have tried storing the data (i.e., Sudheer Kumar) into a cookie using Jquery and also javascript.
But, When storing data into cookie using javascript, data is storing in cookie but without cookie name and also in a string format as shown below
When Storing data into cookie using Jquery, data is storing in cookie but with special characters between for both cookie name and value
Code snippet is pinched below.
Code
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script type="text/javascript">
//Jquery cookie Logic
$(document).ready(function () {
$.cookie('Jquery Cookie Data', 'sudheer Kumar');
cookiemethod();
});
//JavaScript cookie Logic
function cookiemethod() {
document.cookie = 'sudheer Kumar';
}
</script>
Data Stored in browser cookie
click here to see how the data is stored in browser cookie
Finally,please suggest a solution which has name and value format and value should be in string but not with special characters and solution can be either in Javascript or Jquery.
Issue is resolved for JavaScript.
Here is the solution for JavaScript.
//JavaScript cookie Logic
function cookiemethod() {
document.cookie = 'JSCookieName' + "=" + 'sudheer Kumar';
}
If we written the code like this JSCookieName is name of the cookie and next is the cookie value.
Here is the output with cookie Name for Java Script
Need to find solution for Jquery cookie