AJAX post error : Refused to set unsafe header “Connection”

前端 未结 1 1654
谎友^
谎友^ 2020-11-27 18:27

I have the following custom ajax function that posts data back to a PHP file. Everytime the post of data happens I get the following two errors :

1条回答
  •  春和景丽
    2020-11-27 18:35

    Remove these two lines:

    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    

    XMLHttpRequest isn't allowed to set these headers, they are being set automatically by the browser. The reason is that by manipulating these headers you might be able to trick the server into accepting a second request through the same connection, one that wouldn't go through the usual security checks - that would be a security vulnerability in the browser.

    0 讨论(0)
提交回复
热议问题