最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How to Address "Refused to Set Unsafe Header: Connection"? - Stack Overflow

programmeradmin0浏览0评论

I'm using Prototype bined with CodeIgniter to submit an AJAX request. My browser is Chrome. I'm receiving an error in the console that reads "Refused to set Unsafe Header: Connection". Here is the Ajax Request line:

new Ajax.Request('/vbs/index.php/signup/get_ratecenters',{method:'POST', evalScripts:true})

I've attempted to set the type to synchronous, but received the same error.

Can someone assist? Thanks in advance.

I'm using Prototype bined with CodeIgniter to submit an AJAX request. My browser is Chrome. I'm receiving an error in the console that reads "Refused to set Unsafe Header: Connection". Here is the Ajax Request line:

new Ajax.Request('/vbs/index.php/signup/get_ratecenters',{method:'POST', evalScripts:true})

I've attempted to set the type to synchronous, but received the same error.

Can someone assist? Thanks in advance.

Share Improve this question edited Dec 27, 2011 at 16:47 Rob W 349k87 gold badges807 silver badges682 bronze badges asked Aug 25, 2011 at 14:05 Derek BrownDerek Brown 531 silver badge4 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

There's only one code fragment in prototype.js (1.7.0.0) that attempts to set a 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';
}

If you're using a local copy of prototype.js you could change the code fragment to

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';
  }
}

and see if it's really the cause.

What happens if you load /vbs/index.php/signup/get_ratecenters directly in your browser?

I read somewhere online that "Refused to set Unsafe Header: Connection" is a warning that the HTTP "Connection" header cannot be set, but doesn't mean the request will not be processed, so it's possible something else is going on here?

Check /vbs/index.php/signup/get_ratecenters and make sure it returns valid JavaScript code. Execute that code in the Chrome console and make sure it is error free... possibly here's a different error here.

发布评论

评论列表(0)

  1. 暂无评论