Jump to content

AJAX not working in IE


GrF

Recommended Posts

Hi,

I've a problem with my little ajax script. It works in Opera and after some tweaking in Firefox, but IE just shows nothing. I believe it may be something obvious, but I'm quite new to ajax and as a Linux user I generally don't use IE so I don't really know its limitations very well.

Here's the script's source:

function newsPager()
{
this.page = 1;
this.category = 'main';
this.totalPages = null;
this.perPage = 2;
this.order = "timestamp";
this.orderMode = "DESC";
this.xmlHTTP = null;
this.XMLData = null;

this.init = function()
{
	try
	{
		xmlHTTP = new XMLHttpRequest();
	}
	catch(e)
	{
		try
		{
			xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
				alert("You have such a shitty browser that it's AJAX-phoebic. Switch to Opera/Firefox");
			}
		}
	}
	this.xmlHTTP = xmlHTTP;
}

this.stateChanged = function()
{

	//alert(typeof(xmlHTTP));
	if(xmlHTTP.readyState == 4)
	{
		//alert('dzialam');
		//alert("TP: "+ this.totalPages +"\nP: " + this.page );
		//document.getElementById('data').innerHTML = xmlHTTP.responseXML;
		var XMLData = xmlHTTP.responseXML;
		var htmlOutput = "<table cellspacing='0' cellpadding='0' border='0' width='100%'>\n";
		htmlOutput += "<tr><td class='withoutstyles'>\n";
		for(i = 0;i < XMLData.firstChild.childNodes.length;i++)
		{
			var title = XMLData.firstChild.childNodes[i].getAttribute('title');
			var content = XMLData.firstChild.childNodes[i].firstChild.textContent;
			var autor = XMLData.firstChild.childNodes[i].getAttribute('author');
			var time = XMLData.firstChild.childNodes[i].getAttribute('timestamp')
			var id = XMLData.firstChild.childNodes[i].getAttribute('id')
			htmlOutput += "<tr><td class='withoutstyles'>";
			htmlOutput += "<span class='header'><img src='images/bullet.png' alt='' border='0' vspace='2' align='left' />"+title+"</span>\n"
			htmlOutput += "</td></tr><tr><td style='padding-left: 10px; border: none;'>";
			if(XMLData.firstChild.childNodes[i].getAttribute('img') == 'true')
			{
				//alert(id);
				var imgURL = XMLData.firstChild.childNodes[i].getAttribute('imgURL');
				var bigImgURL = XMLData.firstChild.childNodes[i].getAttribute('bigImgURL');
				htmlOutput += "<a href='"+bigImgURL+"' rel='lightbox'><img border='0' style='padding-right: 10px;' align='left' src='"+ imgURL +"' /></a>";
			}
			htmlOutput += "<p class='news' align='justify'>";
			htmlOutput += "<p class='news' align='justify'>";
			htmlOutput += content;
			htmlOutput += "</p>";
			htmlOutput += "<p align='right'><span class='signature'>";
			htmlOutput += "<b>autor: " + autor + "</b>; dodano: " + time;
			htmlOutput += "</p></span>";
			htmlOutput += "</td></tr>";
		}
		this.page = XMLData.firstChild.getAttribute('page');
		this.totalPages = XMLData.firstChild.getAttribute('totalpages');
		htmlOutput += "<tr><td class='withoutstyles' height='12'> </td></tr>";
		htmlOutput += "<tr><td align='center' class='withoutstyles'>";
		if(this.page != 1)
		{
			htmlOutput += "<a href=javascript:nP.prevPage()>poprzednia strona</a> ";
		}
		for(i = 1;i<=this.totalPages;i++)
		{
			if(i == this.page)
			{
				htmlOutput += i+"  "
			}
			else
			{
				htmlOutput += "<a href='javascript:nP.changePage("+i+")'>"+(i)+"</a>  "
			}
		}
		if(this.page != this.totalPages)
		{
			htmlOutput += "<a href='javascript:nP.nextPage()'>nastepna strona</a>";
		}
		htmlOutput += "</table>";
		document.getElementById('data').innerHTML = htmlOutput;
	}
}

this.fetch = function()
{
	if(this.xmlHTTP == null)
		this.init();
		var url="core/pager/pager.php?mode=news&page="+this.page;
		//alert(url);
		var self = this;
		var page = this.page
		this.xmlHTTP.onreadystatechange=this.stateChanged;
		this.xmlHTTP.open("GET",url,true);
		this.xmlHTTP.send(null);
}

this.changePage = function(page)
{
	this.page = page;
	this.fetch();
	//alert(this.page);
}

this.nextPage = function()
{
	this.changePage(this.page+1);
	//this.fetch();
	//alert(this.page);
}

this.prevPage = function()
{
	this.changePage(this.page-1);
	//this.fetch();
	//alert(this.page);
}

this.start = function()
{
	this.init();
	this.fetch();
}

this.changeCategory = function(category)
{
		this.category = category;
		this.fetch();
}
}

var nP = new newsPager();

My first guess would be that I use some kind of unsupported property or method in the part that deals with XML, but I don't have enough experiance with XML and JS to find the error even if it's there.

I'd be grateful for any help you can give

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.