SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2006
    Location
    Manchester; UK
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    AJAX problems with IE

    Basically my friends AJAX news system for Thybag 5 works perfectly in firefox but screws up in IE. As i cant really be arsed to hunt aorund for hours looking for whats wrong, when chances are its stairing me obviosly in the face, im asking here to see anyone with a freash approach and figure out the problem quickly.

    This is copied off my mate, not mine

    The Javascript:

    Code:
    var target ;
    
    function a_edit(id){
    target = 'N_' + id;
    try {xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");}  catch (e) { // DontWork
    }
    xmlhttp.onreadystatechange = b_edit;
    xmlhttp.open("GET", '####&a=addform&id=' + id);
    xmlhttp.send(null);
    
    }
    function b_edit(){
    if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
    document.getElementById(target).innerHTML = xmlhttp.responseText;
    }
    }
    function c_edit(id){
    // Get Data
    var title = document.getElementById("N" + id + "_title").value;
    var cat = document.getElementById("N" + id + "_Cat").value;
    var update = document.getElementById("N" + id + "_time").checked;
    var news = document.getElementById("N" + id + "_NewsItem").value;
    
    xmlhttp.onreadystatechange = d_edit;
    xmlhttp.open("POST", '####&a=save&id=' + id + '', true);
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlhttp.send("title=" + title + "&cat=" + cat + "&update=" + update + "&news=" + news + "");
    
    }
    function d_edit(){
    if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
    
    var rsp = xmlhttp.responseText;
    // Spit Id and responce
    var rsp2 = rsp.split('||--||');
    var loc = 'N_' + rsp2[0];
    //Write responce to ID
    document.getElementById(loc).innerHTML = rsp2[1];
    
    
    } 	
    }
    var adin = 0;
    function n_Add(){
    
    if(adin== 1) {
    }
    else {
    // Load Ajax form for New news
    try {xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");}  catch (e) { // DontWork
    }
    xmlhttp.onreadystatechange = n_Add2;
    xmlhttp.open("GET", '####&a=New_addform');
    xmlhttp.send(null);
    }
    }
    var cur;
    function n_Add2(){
    if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
    cur = document.getElementById('addSpace').innerHTML
    document.getElementById('addSpace').innerHTML = xmlhttp.responseText + cur;
    adin = 1;
    }
    }
    function n_Add3(){
    //
    var title = document.getElementById("New_title").value;
    var cat = document.getElementById("New_Cat").value;
    var news = document.getElementById("New_NewsItem").value;
    
    xmlhttp.onreadystatechange = n_Add4;
    xmlhttp.open("POST", '####&a=addme', true);
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlhttp.send("title=" + title + "&cat=" + cat + "&news=" + news + "");
    
    }
    function n_Add4(){
    if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
    
    document.getElementById('addSpace').innerHTML = xmlhttp.responseText + cur;
    adin = 0;
    }
    }
    
    function delete_N(id) {
       if (confirm('Are you sure you want to delete this News Item?')) {
    // Ajax remove post
    xmlhttp.open("GET", '####&a=del&id=' + id);
    xmlhttp.send(null);
    // Make gone
    document.getElementById('N_' + id).innerHTML = "";
           }
           else {
    // Cancil remove prot
    alert ('Ok, no action has been taken');
       }
    }
    To be on the safe side I #### the URLS until I get around to checking them security wise

    The Code:

    Code:
    <div align="left">
    <div style="padding:6px"><a href="javascript:n_Add();">ADD NEWS BUTTON</a></div><br />
    
    <div id="addSpace"></div>
    
    <div id="N_6">
    
    <a href="javascript:a_edit(6);"><img src="http://thybag.co.uk/forum/style_images/bag/p_edit.gif" alt="Edit" style="border:0; float:right; position:relative;"></a><a href="javascript:delete_N(6);"><img src="http://thybag.co.uk/forum/style_images/bag/p_delete.gif" alt="Delete" style="border:0; float:right; position:relative;"></a>
    
    
    <img src="http://thybag.co.uk/mkportal/modules/gallery/album/t_a_348.jpg" alt="Mentor Avitar" width="106" height="150" style="padding:4px; float:left;  position:relative; z-index:4;">
    
    <h3><a href="#">Netscape Firefox Add</a></h3>
    
    <div style="padding:0px 0px 5px 0px;">
    
    <div align="left">
    Lets see about them there perms ey?<br>My <br>av<br>it <br>ar<br>Its a <br>little<br>big for this<br>new system maybe...<br><br>i think.. or do i <!--emo&:/--><img src='http://thybag.co.uk/forum/html/emoticons/hmm.gif' border='0' style='vertical-align:middle' alt='hmm.gif' /><!--endemo--> <!--emo&:)--><img src='http://thybag.co.uk/forum/html/emoticons/smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /><!--endemo--> YOu suck!
    
    </div>
    <div style="background-color:#CCCCCC; padding:2px;">
    <div style=" float:right; font-weight:bold;">
    0 <a href="#">Comments</a>
    </div>
    By <a href="forum/index.php?showuser=66"><strong>Mentor</strong></a> at 6:24 - 06/04/2006 
    </div>
    
    </div>
    
    </div>
    
    
    <div id="N_4">
    
    <a href="javascript:a_edit(4);"><img src="http://thybag.co.uk/forum/style_images/bag/p_edit.gif" alt="Edit" style="border:0; float:right; position:relative;"></a><a href="javascript:delete_N(4);"><img src="http://thybag.co.uk/forum/style_images/bag/p_delete.gif" alt="Delete" style="border:0; float:right; position:relative;"></a>
    
    
    <img src="http://img107.exs.cx/img107/1092/ufo6ld.gif" alt="Bag Avitar" width="75" height="53" style="padding:4px; float:left;  position:relative; z-index:4;">
    <h3><a href="#">Shizzle</a></h3>
    
    <div style="padding:0px 0px 5px 0px;">
    
    <div align="left">
    I think we have a working news system here! <br>I iz like well Chuffed with dat achivement Ey <!--emo&:D--><img src='http://thybag.co.uk/forum/html/emoticons/biggrin2.gif' border='0' style='vertical-align:middle' alt='biggrin2.gif' /><!--endemo--><br><br>Uz also smellzz
    
    </div>
    <div style="background-color:#CCCCCC; padding:2px;">
    <div style=" float:right; font-weight:bold;">
    0 <a href="#">Comments</a>
    </div>
    By <a href="forum/index.php?showuser=1"><strong>Bag</strong></a> at 12:07 - 05/04/2006 
    </div>
    
    </div>
    
    </div>
    
    
    <div id="N_1">
    
    <a href="javascript:a_edit(1);"><img src="http://thybag.co.uk/forum/style_images/bag/p_edit.gif" alt="Edit" style="border:0; float:right; position:relative;"></a><a href="javascript:delete_N(1);"><img src="http://thybag.co.uk/forum/style_images/bag/p_delete.gif" alt="Delete" style="border:0; float:right; position:relative;"></a>
    
    
    <img src="http://img107.exs.cx/img107/1092/ufo6ld.gif" alt="Bag Avitar" width="75" height="53" style="padding:4px; float:left;  position:relative; z-index:4;">
    <h3><a href="#">Thybag Ajax News Engine Online</a></h3>
    
    <div style="padding:0px 0px 5px 0px;">
    
    <div align="left">
    Yes, i think ive finaly managed to get this thing working. Thybags new system can now be edited without any refreshing, directly where it is via the edit button on the right of each artical. So far the forum parser is working perfectly and provideing the smilys and BB code as it is needed.<br><br>Wooot is my responce <!--emo&:D--><img src='http://thybag.co.uk/forum/html/emoticons/biggrin2.gif' border='0' style='vertical-align:middle' alt='biggrin2.gif' /><!--endemo--><br>PS. I am naked... really naked!<br>PSS. No wait, Thats not me. Just ryan... Why is ryan naked in my room?<br>PSSS. Feel the wind!<br>PSSSS. *Swipes Fan* MINE! *throws tantrum*<br>PSSSSS. I like Pie an i cannot lie!
    
    </div>
    <div style="background-color:#CCCCCC; padding:2px;">
    <div style=" float:right; font-weight:bold;">
    0 <a href="#">Comments</a>
    </div>
    By <a href="forum/index.php?showuser=1"><strong>Bag</strong></a> at 9:41 - 04/04/2006 
    </div>
    
    </div>
    
    </div>
    
    
    
    
    
    
    
    
    
    
    
    <div style="padding:12px">Pages: 1 2 3 4 5 6 .</div> </div></div>
      </div>
    	</div></div></div></div></div></div></div></div>
    
    </div><br>
    <br>
    Any obvious problems which may make IE mess up that you point out will be greatly appreciated by me and my mate.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,036
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)

    Ie Ajax

    IE has 2 ActiveX controls, without wasting too much of my time looking at your code, I only see you trying 1. Try something like this.
    HTML Code:
    /* Create a new XMLHttpRequest object to talk to the Web server */
    var xmlHttp = false;
    /*@cc_on @*/
    /*@if (@_jscript_version >= 5)
     try {
       xmlHttp = new XMLHttpRequest();
        if(xmlHttp)alert("otherBrowser");
      } catch (trymicrosoft) {
        try {
          xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
          if(xmlHttp)alert("Msxml2");
        } catch (othermicrosoft) {
          try {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            if(xmlHttp)alert("Microsoft");
          } catch (failed) {
            xmlHttp = false;
          }
        }
      }
    @end @*/

  3. #3
    SitePoint Member bag's Avatar
    Join Date
    Jun 2006
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Naa, its not the ActiveX controls, although i did try you've version just to be sure.
    The problem seems to be with the

    xmlhttp.onreadystatechange = d_edit;

    Since the next step is simply not activating in IE. My best guess is that IE is not recognizing the state change, Possibly something to do with the fact its sent as a POST and im also setting a request header which i do not in the previous bits, which all work.

    I know the Post data is being sent though, since the database does get updated from the php using them "/
    Ive been googling up for similar problems but so far have found nothing relevant, although allot of the examples seem to be doing pretty much what i am, just without the problems with IE "/
    Am i the only one who finds you spend more time trying to get a site to work properly with IE than you do making the entire site to start with "/


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •