Jump to content

simple ajax framework in ie6 unstable?


domk

Recommended Posts

hi there

 

im now sitting on the problem for more then 8h and just cant get on with it...

ill appreciate any help here :)

 

problem: ajax javascript/php framework

the following code works just fine in any browser but in ie6 where it does not give me any error messages and works only sometimes and other times not at all(what it does then is nothing...)

 

html code here

<script type="text/javascript">
<!--

    function setTitle(title,msgT) {  //...
     alert(msgT);
    }
   
    // Get the HTTP Object
    function getHTTPObject() {   
      try {
        return new XMLHttpRequest();  //return default ajax request
      }
      catch (trymicrosoft) {  //ie
        try {
          return new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (othermicrosoft) {  //ie
          try {
            return new ActiveXObject("Microsoft.XMLHTTP");
          }
          catch (failed) {
            alert("Your browser does not support AJAX.");
            return null;
          }
        }
      }
    }

    // Change the value of the outputText field
    function setOutput() {
     if(httpObject.readyState == 4){
      var responseText = httpObject.responseText;
      eval(httpObject.responseText);  //execute ajax framework
     }
    }

    // Implement business logic
    function doWork(t) {
     httpObject = getHTTPObject();
     if (httpObject != null) {
      httpObject.open("GET", "resource.php?idurl="+t, true);
      httpObject.send(null);
      httpObject.onreadystatechange = setOutput;
     }
    }
   
    var httpObject = null;  //straighten it all out
//-->
</script>

<br><br><br><br>
<a href="javascript:doWork('photos/pic10');">test</a>

 

and the php code in resource.php

<?php

//some connection code missing here... 

$result = mysql_query("select url,title,msg from ".$table." where url = '".trim($_GET["idurl"])."' Limit 1");
$res = mysql_fetch_array($result);

$msgTT=str_replace(" "," ",trim(nl2br(addslashes($res[msg]))));
$msgTT=str_replace("\n","",$msgTT);
$msgTT=str_replace("\r","",$msgTT);


echo '
titleT="'.trim(addslashes($res[title])).'";
msgTT="'.$msgTT.'";

setTitle(titleT,msgTT);';

?>

 

id even try to replace eval() with a simple alert function which seem to have to very same effect...

if anyone can come up with anything here ill be grateful!

cheers

Link to comment
Share on other sites

found the problem which laid in the caching instance of ie6

function doWork(t) {
     httpObject = getHTTPObject();
     if (httpObject != null) {
      var randomID = Math.random() * Date.parse(new Date()); //random string to prevent caching
      httpObject.open("GET", "resource.php?idurl="+t+"&rand="+randomID, true);
      httpObject.send(null);
      httpObject.onreadystatechange = setOutput;
     }

 

thats what it looks like now :)

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.