我将 Prototype 与 CodeIgniter 结合使用来提交 AJAX 请求。我的浏览器是 Chrome。我在控制台中收到一条错误消息,内容为“拒绝设置不安全 header :连接”。这是 Ajax 请求行:
new Ajax.Request('/vbs/index.php/signup/get_ratecenters',{method:'POST', evalScripts:true})
我试图将类型设置为同步,但收到了同样的错误。
有人可以帮忙吗?提前致谢。
最佳答案
prototype.js (1.7.0.0) 中只有一个代码片段尝试设置 Connection: close
header
if (this.method == 'post') {
headers['Content-type'] = this.options.contentType +
(this.options.encoding ? '; charset=' + this.options.encoding : '');
/* Force "Connection: close" for older Mozilla browsers to work
* around a bug where XMLHttpRequest sends an incorrect
* Content-length header. See Mozilla Bugzilla #246651.
*/
if (this.transport.overrideMimeType &&
(navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005)
headers['Connection'] = 'close';
}
如果您使用的是 prototype.js 的本地副本,您可以将代码片段更改为
if (this.method == 'post') {
headers['Content-type'] = this.options.contentType +
(this.options.encoding ? '; charset=' + this.options.encoding : '');
/* Force "Connection: close" for older Mozilla browsers to work
* around a bug where XMLHttpRequest sends an incorrect
* Content-length header. See Mozilla Bugzilla #246651.
*/
if (this.transport.overrideMimeType &&
(navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005)
{
alert("Yes, this is it.");
if ( navigator.userAgent.match(/Gecko\/(\d{4})/) ) {
alert("navigator");
}
headers['Connection'] = 'close';
}
}
看看是否真的是这个原因。
关于php - 如何寻址 "Refused to Set Unsafe Header: Connection"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7191786/