php - 如何寻址 "Refused to Set Unsafe Header: Connection"?

标签 php javascript ajax codeigniter prototypejs

我将 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/

相关文章:

php - 使用可选参数时允许可选的尾部斜杠

javascript - 通过ajax将html输入数组值传递给php脚本

javascript - 原型(prototype)继承场景中的 jquery 绑定(bind)/触发。无法在正确的对象上触发事件

javascript - 在不知道键名的情况下访问 JSON 对象的元素

javascript - Google map v3 infoWindow addDomListener 用于 HTML 按钮

jQuery .ajax() html 响应。查找<正文>

ajax - 轮询、Comet、WebSockets 等

php - 无法检查查询是否返回行

php - 如何使用 "WHERE"和 "IN"正确编写sql查询

php - JavaScript 和 PHP 网页设计