Sourabh Dhiman

Sourabh Dhiman

  • NA
  • 323
  • 53.4k

Cookie in jquery ?

Oct 4 2019 2:21 AM
function setCookie(cname, cvalue, exdays) {
debugger;
var d = new Date();
var cname = "ID";
var cvalue =$("#transactionID").val();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires=" + d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
I will here set cookies value . into cvalue variable.
 
$(document).ready(function () {
console.log("doc ready common js");
$.ajax({
type: "GET",
url: appurl + "common/Intialize",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
// Assigned Returned data to Global variable
$("#transactionID").val(data);
var cvalue;
setCookie("ID", cvalue, 1);
 
 
I want to get this function in this function but here face a problem = cavlue undefine .
 
I want to save cookie value then run this method. Please help me. 
 

Answers (6)