我正在结合使用Prototype和CodeIgniter来提交AJAX请求.我的浏览器是Chrome.我在控制台中收到一个错误,提示“拒绝设置不安全标题:连接”.这是Ajax请求行:
new Ajax.Request('/vbs/index.php/signup/get_ratecenters',{method:'POST', evalScripts:true})
我试图将类型设置为同步,但收到相同的错误.
有人可以协助吗?提前致谢.
解决方法:
prototype.js (1.7.0.0)中只有一个代码片段尝试设置连接:close标头
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';
}
}
看看是否真的是原因.