dpacmittal Posted March 14, 2009 Share Posted March 14, 2009 I am making a chat script. I've got two Ajax requests which i want to work simultaneously. The first request checks for new messages and displays them using long polling method (Thanks to rhodesa for teaching me). The second one check users online and display them in the users online list every 5 seconds. I can get the both to work with frames. But I cant get them to work If I put them on single page. I tried using function startRetrieve() { setInterval("fetchMsg()",500); setInterval("fetchUsers()",5000); } and in the html part: <body onload="startRetrieve()"> but only 1st request seems to work. I tried the frames and got the both working but I don't want to use frames on my website. What is causing this problem? where am i wrong? Quote Link to comment Share on other sites More sharing options...
Floydian Posted March 14, 2009 Share Posted March 14, 2009 you're probably overwriting the xmlhttp request object. you would need to have two of them for that. Suppose your xmlhttp request object is named ajax, then you should make a second one named ajax2 or something different. Quote Link to comment Share on other sites More sharing options...
dpacmittal Posted March 14, 2009 Author Share Posted March 14, 2009 you're probably overwriting the xmlhttp request object. you would need to have two of them for that. Suppose your xmlhttp request object is named ajax, then you should make a second one named ajax2 or something different. Thanks, It solved my problem. One question though, why does it behaves like this? Quote Link to comment Share on other sites More sharing options...
Floydian Posted March 14, 2009 Share Posted March 14, 2009 it's because everything you want to do with a single xmlhttp request object is anchored to that one object. if you send out a request using a variable named "ajax" as your xmlhttp request object, and then overwrite that variable with something else, you lose your anchor. If you have a function that is creating an ajax object for you, make it return a new object. return new ajax; like so (it might take a bit more than that depending on the way you have your function setup, but if you do have a function that creates the object for you, make sure to return a new one of what you make ) 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.