I am trying to do a cross domain ajax request and populate the contents into a DIV in my JSP page, the javascript method I am using is as follows,
function fetchImgLeads(){
var myAjax = new Ajax.Request(
'http://someotherdomain:8080/imghtml?img=100',
{ method:'GET',
parameters:{},
requestHeaders :["Access-Control-Allow-Origin","*","Access-Control-Allow-Methods","POST, GET, OPTIONS","Access-Control-Allow-Headers", "X-PINGOTHER","Access-Control-Max-Age","1728000"],
onSuccess:function(t){
alert(t.responseText.trim());
$('imagediv').update(t.responseText);
},
onFailure:function(t){
//do something
}
}
);
}
I am calling this on load and I see an error that says HTTP/1.1 401 Unauthorized
in the Firefox web console. The same thing works fine in IE. I am using IE 8.0 and Firefox 8 for this.
Apart from the requestHeaders
, Is there something else I have to add?
The Http Headers captured are as follows, even then the ajax request does not seem to be working,
OPTIONS http://www.google.com/ HTTP/1.1
Host: www.google.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Proxy-Connection: keep-alive
Origin: http://localhost:8080
Access-Control-Request-Method: GET
Access-Control-Request-Headers: access-control-allow-headers,access-control-allow-methods,access-control-allow-origin,access-control-max-age,x-prototype-version,x-requested-with
HTTP/1.1 405 Method Not Allowed
Content-Type: text/html; charset=UTF-8
Date: Fri, 25 Nov 2011 05:53:54 GMT
Server: GFE/2.0
Content-Length: 11819
Proxy-Connection: Keep-Alive
Connection: Keep-Alive