SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ajax not working in ie7

    I have created this test page

    http://www.acumendesign.co.uk/acumen_cms/news.php

    it uses ajax. Works fine in all other except ie7

    Ive been using the useful tool firebug which has been great but it does'nt give me errors in ie.

    All I get from ie is:

    Line: 141
    Char: 2
    Error: Invalid argument
    Code: 0
    URL: http://www.acumendesign.co.uk/acumen_cms/news.php

    Strange thing is news.php does not have a line 141

    Any ideas how how to solve this?

    Also does what would be a firebug alternative for ie?

    As always help is greatly appreciated

  2. #2
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,629
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Check out the IE developer toolbar (which effectively got folded into ie8). It should help let you know what the deal is.

    That line 141 is the 141st line of script, not your file.

  3. #3
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I find that when IE references line numbers that don't exist in the file in question, and you are using ajax, that the error normally occurs in the onreadystatechange function somewhere.

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your feedback.

    I have been doing some further digging.

    Is it true that IE does not support responseXML?

  5. #5
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is it true that IE does not support responseXML?
    False.

  6. #6
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    If there was no ie I guess life would be to simple!

    Ok I have been doing some digging which these days I usually seem to find a solution. I took the script that I have running on the page above and removed all the DOM elements that I was trying to build and just ran a simple 'alert'. That worked in ie6 & 7.

    So far so good. I just tried to create a simple <p> element with DOM then populate it with my XML file. all good.

    Now when I try to go back to create the table it does not work. Im a bit stumped.

    If there a correct way to build a table with DOM using XML data for ie?

    Code JavaScript:
    // XML Http Request Object
     
    var http = createRequestObject();
     
    function createRequestObject() {
    	// find the correct xmlHTTP, works with IE, FF and Opera
    	var xmlhttp;
    	try {
      	xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch(e) {
        try {
        	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(e) {
        	xmlhttp=null;
        }
      }
      if(!xmlhttp&&typeof XMLHttpRequest!="undefined") {
      	xmlhttp=new XMLHttpRequest();
      }
    	return  xmlhttp;
    }
     
    // SEND REQUEST
     
    function getNewsCat(str) {
     
    	var url="getcat.php";
    	url=url+"?newscat="+str;
        http.open("GET", url, true);
        http.setRequestHeader('Content-Type',  "text/xml");
        http.onreadystatechange = handleResponse;
    	http.send(null);
    	Scroller.reset
    }
     
    // HANDLE REQUEST
     
    function handleResponse() {
     
        if((http.readyState == 4)&&(http.status == 200)){
     
    // CLASS TO HIGHLIGHT CATEGORY BUTTONS
    	var cat1 = document.getElementById("1");
    	cat1.removeAttribute("class");
     
    	var cat2 = document.getElementById("2");
    	cat2.removeAttribute("class");
     
    // REMOVE OLD TABLE
    	var oldtable = document.getElementById("innertable");
    	var newsHolder = document.getElementById("listitems");
     
        newsHolder.removeChild(oldtable);
     
    //GET XML RESPONSE    
        var xmlDoc = http.responseXML.documentElement;
        var articles = xmlDoc.getElementsByTagName("article");
     
        var cats = xmlDoc.getElementsByTagName("cats");
        var catValue = cats[0].getElementsByTagName("cat")[0].firstChild.nodeValue;
     
     
    	// CREATE NEW TABLE
        var newTable = document.createElement("table");
    	newTable.setAttribute("id", "table");    
     
    		for(var i = 0; i < articles.length; i++){
     
    	// CREATE NEW ROW
    	var newRow = document.createElement("tr");
     
     
    	// CHECKBOX CELL
    	var id = document.createElement("td");
    	id.setAttribute("width", "31");
    	id.setAttribute("id", "id");
        var idValue = articles[i].getElementsByTagName("newsid")[0].firstChild.nodeValue;
     
     
     	var checkbox = document.createElement("input");
     	checkbox.setAttribute("type", "checkbox");
    	id.appendChild(checkbox);
        newRow.appendChild(id);
     
     	// TEXT CELLS
     	var author = document.createElement("td");
     	author.setAttribute("width", "93");
     	author.setAttribute("id", "author");
        var authorValue = articles[i].getElementsByTagName("author")[0].firstChild.nodeValue;
    	author.appendChild(document.createTextNode(authorValue));
        newRow.appendChild(author);
     
     
      	var title = document.createElement("td");
      	title.setAttribute("width", "209");
    	title.setAttribute("id", "title");
        var titleValue = articles[i].getElementsByTagName("title")[0].firstChild.nodeValue;
    	title.appendChild(document.createTextNode(titleValue));
        newRow.appendChild(title);
     
     
     	var lastEdited = document.createElement("td");
    	lastEdited.setAttribute("width", "108");
    	lastEdited.setAttribute("id", "lastEdited");
        var lastEditedValue = articles[i].getElementsByTagName("lastedited")[0].firstChild.nodeValue;	
    	lastEdited.appendChild(document.createTextNode(lastEditedValue));
        newRow.appendChild(lastEdited);
     
     
     	var published = document.createElement("td");
    	published.setAttribute("width", "115");
    	published.setAttribute("id", "	published");
        var publishedValue = articles[i].getElementsByTagName("published")[0].firstChild.nodeValue;
    	published.appendChild(document.createTextNode(publishedValue));
        newRow.appendChild(published);
     
    	// ADD ROW TO TABLE	
        newTable.appendChild(newRow);
     
    		}
     
    	// CREATE NEW INNERTABLE
     
    	var innerTable = document.createElement("div");
    	innerTable.setAttribute("id", "innertable");
    	innerTable.setAttribute("style", "height:370px; overflow:hidden");
    	innerTable.setAttribute("class", "makeScroll");
    	innerTable.setAttribute("onLoad", "Scroller.reset(this);");
        innerTable.appendChild(newTable);
     
     
    	// ADD TABLE TO DOCUMENT		
        newsHolder.appendChild(innerTable);
     
    	// HIGHLIGHT BUTTON		
    	var active = document.getElementById(catValue);
    	active.setAttribute("class", "activecat");
     
    // RESET SCROLLBARS
    	Scroller.reset(innerTable);
     
     
     
     
    	}
    }

  7. #7
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    When you use javascript to build a table, many people forget to include the required tbody element.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  8. #8
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That worked thanks.

    Im confused as to why the dynamic scrollbars don't like to load?


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
  •