Jump to content

[SOLVED] AJAX not woking in IE


Recommended Posts

Hi, Created my first AJAX script , and while it works fine in Firefox, it doesn't work at all in IE, not even a response. Put error messages in and it appears to fail on the part where it replaces the <tr> innerhtml right at the end. Curiously, it also fails the HTML earlier on , so some sort of problem with Getelementbyid?

 

 

====

<script type="text/javascript">

function refreshhandsets(type,point)

{

var point;

var type;

var oldhtml = document.getElementById("sl");

var minpoint = point-7;

var newpointleft = Math.max(1,minpoint);

var newpointright = Math.max(point,8);

alert(document.getElementById('sl').onclick)

var newhtml = "refreshhandsets("+type+","+newpointleft+")";

var newhtmlright = "refreshhandsets("+type+","+newpointright+")";

alert ("about to set attributes");

document.getElementById("sl").setAttribute("onclick",newhtml);

document.getElementById("sr").setAttribute("onclick",newhtmlright);

alert ("now onto ifs");

if (type == 1)

{

document.getElementById("cont").setAttribute("class","selected");

document.getElementById("pg").setAttribute("class","");

}

if (type == 2)

{

document.getElementById("pg").setAttribute("class","selected");

document.getElementById("cont").setAttribute("class","");

}

alert ("about to get objects");

xmlhttp=GetXmlHttpObject();

if (xmlhttp==null)

  {

  alert ("Browser does not support HTTP Request");

  return;

  }

alert ("done http object thing");

var url="ajaxhandsets.php";

url=url+"?type="+escape(type);

url=url+"&point="+escape(point);

alert ("created url");

xmlhttp.onreadystatechange=stateChanged;

xmlhttp.open("GET",url,true);

xmlhttp.send(null);

alert ("end of onclick func");

}

function stateChanged()

{

if (xmlhttp.readyState==4)

{

alert ("recieving response");

var element = document.getElementById("phonephotos");

alert(element.innerHTML);

element.innerHTML = xmlhttp.responseText;

alert ("and finally! updated HTML");

}

}

function GetXmlHttpObject()

{

if (window.XMLHttpRequest)

  {

  // code for IE7+, Firefox, Chrome, Opera, Safari

  return new XMLHttpRequest();

  }

if (window.ActiveXObject)

{

try {

page_request = new ActiveXObject("Msxml2.XMLHTTP")

}

catch (e){

try{

page_request = new ActiveXObject("Microsoft.XMLHTTP")

}

catch (e){}

}

}

else

return null

}

</script>

 

====

 

HTML Snippets :

 

<li id="cont" class="selected" onclick="refreshhandsets(1,1)"><a href="#"><span>contract</span></a></li>

<li id ="pg" onclick="refreshhandsets(2,1)"><a  href="#"><span>pay as you go</span></a></li>

  <a id="sl" class="slide left" href="#"  onclick="refreshhandsets(1,1)"><span>slide left</span></a>           

      <tr id="phonephotos"> ** Lots of images in td's** </tr>

              <a class="slide right" href="#" id="sr" onclick ="refreshhandsets(1,8)"><span>slide right</span></a>

 

Any help much appreciated!

 

 

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.