Hi I am on Firefox 3.6.12...
I have an AJAX function that works in Internet Explorer, but not on Firefox.
The setup goes like this:
There are 2 servers. Server1 and Server2
The javascript is located in Server1 and the servlets are located in Server2.
A proxy server is setup at Server1 to redirect requests to Servlets at Server2 to solve the cross-domain issue.
POST method is used.
In the IE, response is received properly (plaintext).
However, in FF, the request header is mysteriously changed to OPTIONS and there is no response from the server whatsoever.
I have tried installing the CORS filter to enable all cross domain request on the server but it doesn't seem to help. Can anyone help me?
The ajaxFunction() is called from within the webpage. Here is a snippet of my javascript file:
function getXMLObject() //XML OBJECT
{
var xmlHttp = false;
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP") // For Old Microsoft Browsers
// document.write("Old Microsoft Browsers");
}
catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP") // For Microsoft IE 6.0+
// document.write("Microsoft IE 6.0+");
}
catch (e2) {
xmlHttp = false // No Browser accepts the XMLHTTP Object then false
}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest(); //For Mozilla, Opera Browsers
// document.write("Mozilla, Opera Browsers");
}
return xmlHttp; // Mandatory Statement returning the ajax object created
}
var xmlhttp = new getXMLObject(); //xmlhttp holds the ajax object
function ajaxFunction() {
xmlhttp = new getXMLObject();
//if(xmlhttp) {
txtname = document.getElementById("SearchInput");
txtvalue = txtname.value;
//alert("AJAX function - txtvalue: " + txtvalue);
if (/\S/.test(txtvalue)){ //check if textbox is not empty or just contains whitespaces
var url = 'http://msm2.cais.ntu.edu.sg:8095/dmserver/TrieQuery';
xmlhttp.open("POST",url,true); //TrieQuery is the servlet name
xmlhttp.onreadystatechange = handleServerResponse;
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
//xmlhttp.send("query=" + txtvalue); //Posting txtname to Servlet
xmlhttp.send("query=" + encodeURI(encodeURI(txtvalue)));
function handleServerResponse() {
if (xmlhttp.readyState == 4) {
//alert("xmlhttp status" + xmlhttp.status);
//alert(xmlhttp.status);
if(xmlhttp.status == 200 || xmlhttp.status == 0) {
// document.myForm.message.value=xmlhttp.responseText; //Update the HTML Form element
//document.getElementById('productsPreview').innerHTML=xmlhttp.responseText;
sgn_states.length=0; //clears last suggestion array
sgn_hits.length=0; //clears last hit array
sgn_previewDetails.length=0; //clear preview details of last query
//suggestions delimited by "~"
//other details delimited by ":"
//e.g. nike:30,adidas:117,puma:6
var tempStates=xmlhttp.responseText;
//alert("nth");
// document.getElementById('test').innerHTML=xmlhttp.responseText;
var mySplitResult=tempStates.split("~");
for (i=0;i<mySplitResult.length;i++){
var tempItems=mySplitResult[i].split(",");
sgn_states[i]=tempItems[0];
sgn_hits[i]=tempItems[1];
sgn_previewDetails[i]="";
for (j=2;j<tempItems.length;j++){
sgn_previewDetails[i]=sgn_previewDetails[i] + tempItems[j] + ",";
}
}
//alert("HTML- " + previewHTML);
//print row tag for start of every row of 5
// if (i%5==0) previewHTML=previewHTML + "<tr>";
// previewHTML=previewHTML+ "<td><a href='" + tempDetails[i*3+2] + "'><img width='150' height='150' src='"
// + tempDetails[i*3+1] + "'></img></a><br>" + tempDetails[i*3] + "</td>"
//print row closing tag for end of every row of 5
// if (i%5==4) previewHTML=previewHTML + "</tr>";
}
//print row closing tag if table does not end exact at row of 5
//if (tempDetails.length%5!=0) previewHTML=previewHTML + "</tr>";
//previewHTML=previewHTML + "</table>";
Bookmarks