Reputation: 17116
When I try to send an HTTP GET request through XMLHttpRequest it works on non-secure HTTP.
But when sent over HTTPS, different browsers gave different results:
On Firefox 3.0.2: - The GET request doesn't reach the web server.
On IE 7: - The GET request reached the web server.
Does this have something to do with Firefox 3 getting stricter with untrusted certificates? Is there a way around this?
I've already added the URL as an exception in Firefox's Certificate Manager. The error console doesn't report any error. I've added a try-catch around XMLHttpRequest's open() and send. No exception is thrown.
Using both absolute and relative URL path doesn't work.
Here's the code snippet:
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
return false;
}
}
}
// we won't be handling any HTTP response
xmlHttp.onreadystatechange=function()
{
// do nothing..
}
// send HTTP GET request
try
{
xmlHttp.open("GET", "/[relative path to request]", true);
xmlHttp.send(null);
}
catch (e)
{
alert('Error sending HTTP GET request!');
return false;
}
Thanks, Kenneth
Upvotes: 3
Views: 14076
Reputation: 4966
Try placing your closure after the open:
// send HTTP GET request
try
{
xmlHttp.open("GET", "/[relative path to request]", true);
}
catch (e)
{
alert('Error sending HTTP GET request!');
return false;
}
// we won't be handling any HTTP response
xmlHttp.onreadystatechange=function()
{
// do nothing..
}
// Then send it.
xmlHttp.send(null);
A little googling found confirmation: http://www.ghastlyfop.com/blog/2007/01/onreadystate-changes-in-firefox.html
Although that document says to attach the function after .send(null), I've always attached after open.
Upvotes: 1
Reputation: 200826
By any chance, are you requesting a non-HTTPS URL in an HTTPS page? Do any messages appear in the error log/console?
Upvotes: 0