Jump to content

Recommended Posts

This is my JS file

// JavaScript Document

function createhandler() 
{
var xmlhttp;

if (window.XMLHttpRequest) 
{
  xmlhttp = new XMLHttpRequest();
}

else if (window.ActiveXObject) 
{
  xmlhttp =  new ActiveXObject("Msxml2.XMLHTTP");
}
return xmlhttp;
}


function chatarea()
{	
var xmlhttp=createhandler();

xmlhttp.onreadystatechange=function () 
{ 
	if(xmlhttp.readyState==4)
	{

	document.getElementById("chatroom").innerHTML=xmlhttp.responseText;

	xmlhttp.onreadystatechange = null;

	xmlhttp.abort();

	}	
};

	xmlhttp.open('GET', 'chat.php', true);

	xmlhttp.send(null);

	var t = setTimeout("chatarea()",1000);

	return true;
}

function addchat()
{
var xmlhttp=createhandler();
xmlhttp.onreadystatechange=function () 
{ 
	if(xmlhttp.readyState==4)
	{

		document.getElementById("error").innerHTML=xmlhttp.responseText;

		xmlhttp.onreadystatechange = null;

		xmlhttp.abort();

	}

};

var message = document.getElementById('chatenter').value;

var params = 'message='+message;

xmlhttp.open('POST', 'createchat.php', true);

xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

xmlhttp.setRequestHeader("Content-length", params.length);

xmlhttp.setRequestHeader("Connection", "close");

xmlhttp.send(params);   

return true;	

}

 

And the problem is in IE, it will still insert the chat message but wont load the new posts , any ideas why, it works fine in Firefox,Chrome and i think Safari.

 

Any help would be good.

 

Using Chromes javascript debugger , i get this when i post .

 

JavaScript Debugger

attached to Chat Room

"Refused to set unsafe header Content-length," source:  (1)

"Refused to set unsafe header Connection," source:  (1)

 

Any one know what it means?

Link to comment
https://forums.phpfreaks.com/topic/122549-ajax-not-working-in-ie-why/
Share on other sites

I use something like this, seems to work in most browsers:

<script type="text/javascript">
function newXHRO()
{
  try { return new XMLHttpRequest(); } catch(e) {}
  try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
  try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
  alert("XMLHttpRequest not supported");
  return null;
}

function someAjax()
{
  var XHRO = new newXHRO();
  var url = 'somefile.php';
  
  XHRO.onreadystatechange=function()
  {
    if(XHRO.readyState==4 && XHRO.status==200)
    {
      alert(XHRO.responseText);
    }
  }
  
  XHRO.open("GET",url,true);
  XHRO.send(null);

}
</script>

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.