3

来自: http ://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader-method

client.setRequestHeader() 
    Appends an header to the list of author request headers, or if
    header is already in the list of author request headers, combines 
    its value with value.

问:有没有办法只设置一个标题而不是附加到现有的?

我正在使用的代码如下,基本上是从https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ajax复制和粘贴的:

jQuery(document).ajaxSend(function(event, xhr, settings) {
     ...

     // xhr is an XMLHttpRequest object
     xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
}
4

0 回答 0