Jquery와 JavaScript를 사용하여 사용자 세션의 유효성을 검사해야 할 때 장고가 CSRF 토큰을 얻기 위해 사용하는 함수를 살펴 보았습니다. 여기에 코드입니다 :JavaScript의 문자열 비교 문제
function getCookie(name) {
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;
}
var csrftoken = getCookie('csrftoken');
당신은 또한 djangoproject 웹 사이트, here 온라인 여기에 코드를 볼 수 있습니다.
Binary operation argument type String is not assignable to type HTMLCollection
가이 무엇을 의미합니까 : 나는이 코드를 붙여 넣을 때 좋아
지금, 나는이 말을 내 IDE에서 빛 경고를?
document.cookie && document.cookie != ''
어떤 줄에 오류가 발생합니까? 이것은 911에 전화를 걸어 주소를 알려주지 않는 것과 같습니다. 줄 번호주세요! –
재미 있은 남자 ... @ ŠimeVidas –
어떤 IDE에 대해 이야기하고 있습니까? JavaScript 코드에 오류 메시지가 적용되지 않습니다. – Pointy