This is my pagination script and i wonder why im getting these errors in IE :
function GetXmlHttpObject(){
var a;
try{
a=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(d){
try{
a=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(c)
{a=false;}
}
if(!a&&typeof XMLHttpRequest!="undefined")
{
try{
var a=new XMLHttpRequest();
}
catch(d){
var a=false;
}
}
return(a);
}
var i=0;var ii=0;var b=0;var bb=0;
function ForumPagination(c){
document.getElementById("forumsblock").style.display="none";
document.getElementById("WaitDiv").innerHTML="<img src='images/loading.gif' >";
xmlHttp=GetXmlHttpObject();
if(xmlHttp==null){
alert("Your browser does not support AJAX!");
return;
}
var a="ind开发者_StackOverflow中文版ext.php?name=Dynamic_forums&pagenum="+c;
xmlHttp.open("GET",a,true);xmlHttp.onreadystatechange=ReplyLoading;xmlHttp.send(null);
}
function ReplyLoading(){
if(xmlHttp.readyState==2||xmlHttp.readyState==4){
var a=xmlHttp.responseText;
document.getElementById("WaitDiv").innerHTML=""+a;
}
}
script works fine in FF
btw when i change a page i cant do it again .
Webpage error details
Message: 'getLoad' is undefined Line: 105 Char: 311 Code: 0 URI: http://nukelearn.com/
Message: The data necessary to complete this operation is not yet available.
Line: 9 Char: 74 Code: 0 URI: http://nukelearn.com/includes/199233334JOE.js
Message: Object required Line: 3 Char: 1 Code: 0 URI: http://nukelearn.com/includes/199233334JOE.js
Message: Object required Line: 3 Char: 1 Code: 0 URI: http://nukelearn.com/includes/199233334JOE.js
Message: Object required Line: 3 Char: 1 Code: 0 URI: http://nukelearn.com/includes/199233334JOE.js
Message: Object required Line: 3 Char: 1 Code: 0 URI: http://nukelearn.com/includes/199233334JOE.js
Message: Object required Line: 3 Char: 1 Code: 0 URI: http://nukelearn.com/includes/199233334JOE.js
Message: Object required Line: 3 Char: 1 Code: 0 URI: http://nukelearn.com/includes/199233334JOE.js
Message: Object required Line: 3 Char: 1 Code: 0 URI: http://nukelearn.com/includes/199233334JOE.js
Do yourself a favor and use jQuery: you won't have to deal with browser specific issues anymore (at least for javascript)
You first error is because of this statement in your page:
window.onload = getLoad;
There is no getLoad function, which is why that error occurs. That error isn't specific to IE either, the same problem exists whatever the browser.
The second set of errors are caused by a misunderstanding of what the different readyState values in XmlHttp mean. This line is the issue:
if(xmlHttp.readyState==2||xmlHttp.readyState==4){
To quote from the MSDN docs, readyState 2 is:
2 (Sent) The send method has been called. responseText is not available. responseBody is not available.
You appear to be treating readyState 2 as the request having been completed (and then try and use the responseText property), which I expect is what is causing the problem. Change that line to:
if(xmlHttp.readyState==4){
See this question for a discussion of the different readyState values (summary: only ever use 4).
And to reiterate what the other answers have said, use jQuery or at least another smaller library that will abstract away the cross browser XmlHttp nastiness.
I agree with @kemp. If you use jQuery all of your problems will melt away.
Here is a pagination plugin for jQuery, that should meet your needs.
http://tympanus.net/codrops/2009/11/17/jpaginate-a-fancy-jquery-pagination-plugin/
Replace your first function with:
function GetXmlHttpObject(){
return !!window.XMLHttpRequest ? window.XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP");
}
Hopefully that's the source of your headache.
精彩评论