Get response header jquery ajax post Set-Cookie

前端 未结 1 880
梦如初夏
梦如初夏 2021-01-18 07:48

I am using YouTrack for our tracking system. Youtrack comes with a rest webservice that you can call to get information from the system. I am having problem getting authoriz

相关标签:
1条回答
  • 2021-01-18 08:16

    Try this:

    function createCookie(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=/";
    }
    
    $.post(youTrackLoginUrl, { login: "restUser", password: "qwerty" }, function(data, text, xhr) {
    
      data_set_cookie = data.match(/Set-Cookie:\s([^;]+);/)[1];
      createCookie(data_set_cookie.split("=")[0],data_set_cookie.split("=")[1],365); //sets cookie for 1 year
    
    });
    
    0 讨论(0)
提交回复
热议问题