2014-12-29 3 views
1

java ee 응용 프로그램을 개발 중이며 다른 사용자에게 동일한 쿠키를 사용하는 한 페이지가 있습니다. 그래서 jquery.cookie.js 파일을 복사하고 jquery.cookie2.js라는 이름으로 새 파일을 만들었고 호출 스크립트도 변경했습니다. 그러나 작동했지만 동일한 동작을합니다. 이전 사용자에서 내가 한 일은 무엇이든 새로운 것으로 발생합니다. 나는 그것이 작동하지 않았다 후두 개의 jquery 쿠키를 설정하는 방법은 무엇입니까?

jQuery.cookie2 

jQuery.cookie 

에서 변경 있도록 쿠키 이름이 될 줄 알았는데. 여기

jQuery.cookie = function(name, value, options) { 
if (typeof value != 'undefined') { // name and value given, set cookie 
    options = options || {}; 
    if (value === null) { 
     value = ''; 
     options.expires = -1; 
    } 
    var expires = ''; 
    if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { 
     var date; 
     if (typeof options.expires == 'number') { 
      date = new Date(); 
      date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); 
     } else { 
      date = options.expires; 
     } 
     expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE 
    } 
    // CAUTION: Needed to parenthesize options.path and options.domain 
    // in the following expressions, otherwise they evaluate to undefined 
    // in the packed version for some reason... 
    var path = options.path ? '; path=' + (options.path) : ''; 
    var domain = options.domain ? '; domain=' + (options.domain) : ''; 
    var secure = options.secure ? '; secure' : ''; 
    document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); 
} else { // only name given, get cookie 
    var cookieValue = null; 
    if (document.cookie && document.cookie != '') { 
     var cookies = document.cookie.split(';'); 
     for (var i = 0; i < cookies.length; i++) { 
      var cookie = jQuery.trim(cookies[i]); 
      // Does this cookie string begin with the name we want? 
      if (cookie.substring(0, name.length + 1) == (name + '=')) { 
       cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); 
       break; 
      } 
     } 
    } 
    return cookieValue; 
} 
}; 

내 질문은 하나의 응용 프로그램에 대해 서로 다른 쿠키를 사용하는 방법은 쿠키에 대한 코드는?

답변

0

방금 ​​쿠키 모듈의 소스 코드를 복사하여 붙여 넣었으므로 도움이되지 않습니다. jquery.cookie2.js를 제거하십시오. 두 개의 서로 다른 쿠키를 사용하려는 경우, 다음 두 가지 쿠키의 값을 설정합니다

//Set values 
$.cookie('user1', 'firstValue'); 
$.cookie('user2', 'differentValue'); 

//Retrieve values 
$.cookie('user1'); //Returns 'firstValue' 
$.cookie('user2'); //Returns 'differentValue' 

나는 당신이 당신의 목표는 몇 가지 정보를 클라이언트 측을로드하는 것입니다 특히,하지만 쿠키를 사용할 필요가 있는지 모르겠어요 동일한 컴퓨터/브라우저에있는 여러 사용자에게 제공됩니다. localStorage을 사용하는 대체 방법에 대한 자세한 내용은이 답변을 참조하십시오. 특히 페이지로드시마다 서버에 정보를 보내지 않아도되는 경우에는 https://stackoverflow.com/a/28253089/830125을 사용하십시오.

관련 문제