Jump to content

Simple ajax chat question


squiblo

Recommended Posts

I have made a good working chat and these are the steps the chat goes through to output new messages.

 

1. Count number of words in the chat .txt file

2. Count number of words in the div where the chat is outputted

3. If the word counts are both the same check again

4. If they are different then the div innerHTML will = the chat .txt file

 

the problem is that i want it to me milliseconds faster, and counting words does not seems the most logical way to check if they are different. Any ideas?

 

Thanks

Link to comment
Share on other sites

becuase using innerHTML slightly changes code for example

 

in IE

<span id='test' style='color:red'> will change to <SPAN id=test STYLE="color:red">

 

but in firefox innerHTML changes the code differently, so they could be the same in some browsers but maybe not in others, if you get me

Link to comment
Share on other sites

That doesn't seem right. Browsers don't inject HTML, they just display what you coded. Plus, if that was the case, the string length of <span id='test' style='color:red'> and <SPAN id=test STYLE="color:red"> are not the same, due to the missing single quotes around "test."

Link to comment
Share on other sites

I have just done a check..

 

this is a sample of what is in my .txt file (just entering random gibberish)

 

<LI>VFOMB<INPUT type="hidden" value="administrator1"></LI>

<LI>ORROR<INPUT type="hidden" value="administrator1"></LI>

<LI>GVVMF<INPUT type="hidden" value="administrator1"></LI>

<LI>FOEFMVE<INPUT type="hidden" value="administrator1"></LI>

<LI>EVORG<INPUT type="hidden" value="administrator1"></LI>

<LI>RGOVK,R<INPUT type="hidden" value="administrator1"></LI>

 

but when i alert what is in the content of the div where the chat is outputted it shows this...

 

<li>VFOMB<input type="hidden" value="administrator1"></li>

<li>ORROR<input type="hidden" value="administrator1"></li>

<li>GVVMF<input type="hidden" value="administrator1"></li>

<li>FOEFMVE<input type="hidden" value="administrator1"></li>

<li>EVORG<input type="hidden" value="administrator1"></li>

<li>RGOVK,R<input type="hidden" value="administrator1"></li>

 

here I used google chrome, and in IE it changes tags into capitals

Link to comment
Share on other sites

You could do a replace on both, just replace all double quotes with singles, again just for the compare.

 

Really, you should just put this into a database. Then you could store the ID of the most recent chat in a hidden input, then add any new lines and update the latest ID. That would be faster yet, because you could then just add the new data to the field, rather than replacing the whole thing.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.