CSRF保护导致“类型不匹配错误”

时间:2012-05-14 17:31:24

标签: javascript django csrf satchmo

在Satchmo代码(satchmo / satchmo / apps / satchmo_store / contact / templates / contact / _state_js.html)中,以下JavaScript在Internet Explorer版本6中导致错误:

/**
* Required for Django's CSRF protection when using AJAX
* Taken from here - http://docs.djangoproject.com/en/dev/ref/contrib/csrf/
*/

$('html').ajaxSend(function(event, xhr, settings) {
    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;
    }
    if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
        // Only send the token to relative URLs i.e. locally.
        xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
    }
});

具体而言IE引用以下行:

xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));

问题出现在包含“Country”和“Province”的表单中。显然,如果国家发生变化,那么可用的省份必须改变。一旦用户选择国家/地区,资源管理器就会报告此错误:

Line: 239
Char: 9
Error: Type mismatch
Code: 0
URL: http://10.1.1.7:8000/checkout/

有谁可以提出问题在这里?我真的不明白为什么它应该是“类型不匹配”?

非常感谢,托马斯

0 个答案:

没有答案