Click to See Complete Forum and Search --> : Ajax cross browser compatibility??


tomfmason
09-28-2006, 12:38 AM
I have written a relatively simple chat script. The issue that I am having is that the results are not shown in FireFox or Opera but are fine in IE 6. I am not exactly sure what the issue is. Well I have narrowed it down to the function that gets the chat text.

here are the functions that retrieve the chat text.


function getChat() {
getText.open('get', 'process.php?action=getChat');
getText.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
getText.onreadystatechange = handleGetChat;
getText.send(null);
}

function handleGetChat() {
if (getText.readystate == 4) {
var chat = document.getElementById('chatBox');
var chatText = getText.responseText;
chat.innerHTML = chatText;
chat.scrollTop = chat.scrollHeight;
//chatTimer is a global variable
chatTimer = setTimeout('getChat();', 2000);
}
}

I have heard that Opera was good for displaying errors. It shows none. However, FireFox shows one..


Error: junk after document element
Source File: http://www.mysite.com/process.php?action=getChat[/url]
Line: 1, Column: 11
Source Code:
<b>Tom</b>: Opera is not showing any errors and at the same time is not showing any results<br />
-----------^


I thought that maybe I needed to escape the : so I just removed it. The column just moved to 13. So Then I thought maybe it was the <b> </b> 's . So I removed them..

Now I am getting the following error.


Error: syntax error
Source File: http://www.mysite.com/process.php?action=getChat
Line: 1, Column: 1
Source Code:
Tom Opera is not showing any errors and at the same time is not showing any results<br />


I have I have tried every thing that I can think of except throwing in some alerts to see where in the process it is having the problem..

Has anyone had similar issues?

I knew that I was going to have issues with making it compatible with Netscape Navigator but did not think I would have any with Mozilla..

Any suggestions would be great..

Thanks,
Tom

felgall
09-28-2006, 01:42 AM
Try changing get to GET as it is supposed to be case sensitive and that is supposed to be uppercase.

tomfmason
09-28-2006, 02:35 AM
Thanks for the reply. I tried that and no change..

Aparrently the issue is in the format that I am returning the results. As I posted in the last post. FireFox is getting the results but is throwing out an error. Opera is not showing results or errors. IE 6 is fine..

I am lost on this one. I think that it is a rather simple problem but the answer is eluding me.

Thanks again,
Tom

tomfmason
09-28-2006, 03:10 AM
I have got it to work in FireFox now...

I told you that I thought it was a rather simple fix..lol

it was the

if (getText.readystate == 4) {

it is readyState not state

Thanks for the suggestions..

Tom

dungsport
09-28-2006, 03:13 AM
I'm not sure this will directly help you solve the problem. It's just my comment. Moreover, you did not show how the getChat() get called and how getText (XMLHttpRequest) is declared.

getText.open(method, url, true);

Open method should have the third parameter telling it to be asynchronous.

If it is possible, give us a link to your page so that everyone can pinpoint it out.

Cheers,

tomfmason
09-28-2006, 04:05 AM
I used a fairly standard method of createing the XMLHttpRequest.. Which is working fine. I knew that it was working since the text was being imputed into the database.. This is what told me that the issue had to be with the getChat function.

here is the createRequestObject function.


function createRequestObject()
{
if (window.XMLHttpRequest) { // Mozilla, Safari, Opera...
var xmlhttp = new XMLHttpRequest();
if (xmlhttp.overrideMimeType)
xmlhttp.overrideMimeType('text/xml');
}
else if (window.ActiveXObject)
{ // IE
try {
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}

if (!xmlhttp) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
return xmlhttp;
}

var getText = createRequestObject();

as you can tell it is rather simple and works fine.

Thanks,
Tom

dungsport
09-28-2006, 06:07 AM
I think I encountered this before. It's caused by the order of statements. Try to set onreadystatechange first of all, like followings:

getText.onreadystatechange = handleGetChat;
getText.open('get', 'process.php?action=getChat');
getText.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
getText.send(null);

A1ien51
09-28-2006, 07:29 AM
It is better practice to put onreadystate after the open statement.

Eric