Jump to content

AJAX IE7 fails after 2 clicks


hansford

Recommended Posts

Heres the js file code

function get_page(page) {

var httpRequest;


if (window.XMLHttpRequest) { 
    httpRequest = new XMLHttpRequest();
}
else if (window.ActiveXObject) { 

     var ieXmlHttpVersions = new Array();
ieXmlHttpVersions[ieXmlHttpVersions.length] = "MSXML2.XMLHttp.7.0";
ieXmlHttpVersions[ieXmlHttpVersions.length] = "MSXML2.XMLHttp.6.0";
ieXmlHttpVersions[ieXmlHttpVersions.length] = "MSXML2.XMLHttp.5.0";
ieXmlHttpVersions[ieXmlHttpVersions.length] = "MSXML2.XMLHttp.4.0";
ieXmlHttpVersions[ieXmlHttpVersions.length] = "MSXML2.XMLHttp.3.0";
ieXmlHttpVersions[ieXmlHttpVersions.length] = "MSXML2.XMLHttp";
ieXmlHttpVersions[ieXmlHttpVersions.length] = "Microsoft.XMLHttp";
var i;
  for (i=0; i < ieXmlHttpVersions.length; i++)
  {
   try
   {
    httpRequest = new ActiveXObject(ieXmlHttpVersions[i]);

   }
   catch (e)
   {
    alert(ieXmlHttpVersions[i] + " not supported.");
   }
  }

}
if(document.getElementById('article_no')){
article = document.getElementById('article_no').value;
}
else{
article = page;
}
if(typeof(httpRequest) != 'undefined')
{
var url = 'requestarticle.php?page=';
httpRequest.open('GET',url + article, true);
httpRequest.send(null);

httpRequest.onreadystatechange= function() {

if(httpRequest.readyState==4)
  {

var content = httpRequest.responseText;

document.getElementById("admin").innerHTML = content;


  }
  }

}
}

heres the html file

<html>
<script language='javascript' src='ajax_request_db.js'></script>
<body>
<div id='admin'>
<table width="400" border="1" align="center">
  <tr>
  <td align="center" colspan="2"><h1>Articles<br/><br/></td>

  </tr>
    <tr>
    <td align="center" colspan="2"><div id='auth'></div></td>

  </tr>
  <tr><form action="" method="post" name="adminlogin">
    <td align="right">Article number:</td><td><input type='text' id='article_no' size="10" maxlength="6"></td>
</tr><tr>

  <td colspan="2"><input type="button" name='fetch' id='fetch' value="Get Article" onclick="get_page('fetch');"/></td>
  </tr></form>
</table>
<p> </p>
</div>
</body>
</html>

Link to comment
Share on other sites

I solved the immediate problem. IE does have some issues, but I can't quite pin the documentation of the problem/problems down.

I tweaked my code following this example and it worked as far as this issue is concerned.

http://www.phpfreaks.com/forums/index.php/topic,115581.0.html

The key from the example is all the if/else conditions right down to a complete failure. My original code was similar to this, but I didn't have all the conditions as -why would they be needed-but it seems they are-for IE anyways. If you can't get your code running from this example, then reply and I will post my code as an example.

NOTE: the entire code including checking for the ajax object needs to be contained in one function otherwise you will have problems in IE.

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.