- Joined
- Sep 27, 2010
- Messages
- 2
- Reaction score
- 0
Hey friends....
I am making one simple chat application in asp.net using JAVASCRIPT which is working fine with other browsers EXCEPT InternetExplorer
here is my code...
<script type="text/javascript">
var sTimeInterval;
function timedRefresh()
{
sTimeInterval = setTimeout("SetUrl()",4000);
}
function GetXmlHttpObject(handler)
{
var objXmlHttp = null;
if (navigator.userAgent.indexOf("Opera") >= 0)
{
alert("This example doesn't work in Opera")
return
}
var xmlHttp = null;
if (window.XMLHttpRequest)
{
objXmlHttp = new XMLHttpRequest();
objXmlHttp.onload = handler;
objXmlHttp.onerror = handler;
return objXmlHttp;
}
else
{
if (window.ActiveXObject)
{
try
{
objXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
objXmlHttp.onreadystatechange = handler;
return objXmlHttp
}
catch (e)
{
alert("Error. Scripting for ActiveX might be disabled")
return
}
}
}
}
function SetUrl()
{
var url = "Default2.aspx?Type=Receive&DateTime="+ document.getElementById('hid_DateTime').value;
xmlHttp = GetXmlHttpObject(getChatHistory);
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
function getChatHistory()
{
if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
{
document.getElementById('hid_DateTime').value = xmlHttp.responseText.substring(xmlHttp.responseText.lastIndexOf("~")+1);
var sChatHistory = xmlHttp.responseText.substring(0,xmlHttp.responseText.lastIndexOf("~"));
if( sChatHistory != "")
{
document.getElementById('div_ChatHistory').innerHTML += sChatHistory;
var objDiv = document.getElementById("div_ChatHistory");
objDiv.scrollTop = objDiv.scrollHeight;
}
clearTimeout(sTimeInterval);
timedRefresh();
}
}
function send()
{
var url = "Default2.aspx?Type=Send&Message=" + document.getElementById('txt_Msg').value;
document.getElementById('div_ChatHistory').innerHTML += "<br > <strong> "+document.getElementById('hid_UserName').value + " : </strong>" + document.getElementById('txt_Msg').value;
document.getElementById('txt_Msg').value = "";
xmlHttp = GetXmlHttpObject();
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
var objDiv = document.getElementById("div_ChatHistory");
objDiv.scrollTop = objDiv.scrollHeight;
}
function CheckKey(e)
{
if(e == 13)
{
send();
e.Cancel = true;
return false;
}
}
</script>
AFTER JAVASCRIPT DEBUGGING I found that
following function of above code is not being called in internet explorer
function getChatHistory()
{
if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
{
document.getElementById('hid_DateTime').value = xmlHttp.responseText.substring(xmlHttp.responseText.lastIndexOf("~")+1);
var sChatHistory = xmlHttp.responseText.substring(0,xmlHttp.responseText.lastIndexOf("~"));
if( sChatHistory != "")
{
document.getElementById('div_ChatHistory').innerHTML += sChatHistory;
var objDiv = document.getElementById("div_ChatHistory");
objDiv.scrollTop = objDiv.scrollHeight;
}
clearTimeout(sTimeInterval);
timedRefresh();
}
Any one have solution??
Thanks and Regards
MoKsH Shah
I am making one simple chat application in asp.net using JAVASCRIPT which is working fine with other browsers EXCEPT InternetExplorer
here is my code...
<script type="text/javascript">
var sTimeInterval;
function timedRefresh()
{
sTimeInterval = setTimeout("SetUrl()",4000);
}
function GetXmlHttpObject(handler)
{
var objXmlHttp = null;
if (navigator.userAgent.indexOf("Opera") >= 0)
{
alert("This example doesn't work in Opera")
return
}
var xmlHttp = null;
if (window.XMLHttpRequest)
{
objXmlHttp = new XMLHttpRequest();
objXmlHttp.onload = handler;
objXmlHttp.onerror = handler;
return objXmlHttp;
}
else
{
if (window.ActiveXObject)
{
try
{
objXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
objXmlHttp.onreadystatechange = handler;
return objXmlHttp
}
catch (e)
{
alert("Error. Scripting for ActiveX might be disabled")
return
}
}
}
}
function SetUrl()
{
var url = "Default2.aspx?Type=Receive&DateTime="+ document.getElementById('hid_DateTime').value;
xmlHttp = GetXmlHttpObject(getChatHistory);
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
function getChatHistory()
{
if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
{
document.getElementById('hid_DateTime').value = xmlHttp.responseText.substring(xmlHttp.responseText.lastIndexOf("~")+1);
var sChatHistory = xmlHttp.responseText.substring(0,xmlHttp.responseText.lastIndexOf("~"));
if( sChatHistory != "")
{
document.getElementById('div_ChatHistory').innerHTML += sChatHistory;
var objDiv = document.getElementById("div_ChatHistory");
objDiv.scrollTop = objDiv.scrollHeight;
}
clearTimeout(sTimeInterval);
timedRefresh();
}
}
function send()
{
var url = "Default2.aspx?Type=Send&Message=" + document.getElementById('txt_Msg').value;
document.getElementById('div_ChatHistory').innerHTML += "<br > <strong> "+document.getElementById('hid_UserName').value + " : </strong>" + document.getElementById('txt_Msg').value;
document.getElementById('txt_Msg').value = "";
xmlHttp = GetXmlHttpObject();
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
var objDiv = document.getElementById("div_ChatHistory");
objDiv.scrollTop = objDiv.scrollHeight;
}
function CheckKey(e)
{
if(e == 13)
{
send();
e.Cancel = true;
return false;
}
}
</script>
AFTER JAVASCRIPT DEBUGGING I found that
following function of above code is not being called in internet explorer
function getChatHistory()
{
if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
{
document.getElementById('hid_DateTime').value = xmlHttp.responseText.substring(xmlHttp.responseText.lastIndexOf("~")+1);
var sChatHistory = xmlHttp.responseText.substring(0,xmlHttp.responseText.lastIndexOf("~"));
if( sChatHistory != "")
{
document.getElementById('div_ChatHistory').innerHTML += sChatHistory;
var objDiv = document.getElementById("div_ChatHistory");
objDiv.scrollTop = objDiv.scrollHeight;
}
clearTimeout(sTimeInterval);
timedRefresh();
}
Any one have solution??
Thanks and Regards
MoKsH Shah