Reputation: 53
I'm using Prototype combined 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.
Upvotes: 3
Views: 5030
Reputation: 96159
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.
Upvotes: 4
Reputation: 11070
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.
Upvotes: 0