sazzie Posted January 9, 2007 Share Posted January 9, 2007 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? Quote Link to comment Share on other sites More sharing options...
tomfmason Posted January 9, 2007 Share Posted January 9, 2007 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 Quote Link to comment Share on other sites More sharing options...
sazzie Posted January 9, 2007 Author Share Posted January 9, 2007 Thank you very much Tom. That works now.I never noticed I wasn't using the RMLHttpRequest object - it was a piece of code I lifted from the internetas I was experienting with potential solutions to my problem at the time.Thanks again. ;) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.