Jump to content

[SOLVED] Firefox getResponseHeader Alternative


sazzie

Recommended Posts

Hi everyone,

I was looking for a way to get my ajax application to responde differently to text and XML in my javascript code.

I found "getResponseHeader" which gets the content-type header. You can then compare against strings to see if its xml or html output, as below :

[code][color=red]
var cType = this.getResponseHeader("Content-Type");
alert("Content-Type : "+cType);
if (cType == "text/xml")
{
                                // act on XML output
}
else if (cType == "text/html")
{
//act on html page
}
else
alert("This Sucks! : "+cType);[/color][/code]

The problem is, "getResponseHeader" doesn't seem to be suported by firefox.

Does anyone know of a work around?
getResponseHeader is supported in FF.. Just not in the way that you are trying to use it.. It is supposed to be used within an XMLHTTPRequest..

Here is an example that worked fine in FF..

http is my function were I create the XMLHTTPRequest instance..
[code]
function sendRequest() {
http.abort();
http.open('POST', 'includes/process.php?action=getTime');
http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http.send('do=getTime');
http.onreadystatechange = handleRequest;
    setTimeout('sendRequest()', 1000);
}

function handleRequest() {
if (http.readyState == 4) {
var response = http.responseText;
document.getElementById('time').innerHTML = response;
                //in this case it will alert text/html
alert(http.getResponseHeader('Content-Type'));
}
}
[/code]

I don't think that you can use it out side of a XMLHTTPRequest..


Good Luck,
Tom

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.