clicking on of the buttons calls the proper javascript function, which makes the http request, and dumps that into the "admin_box" div
here is the javascript:
Code:
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}
var http = createRequestObject();
function getUsers() {
http.open('get', 'rpc/users.php?rand=' + Math.random() );
http.onreadystatechange = handleAdmin;
http.send(null);
}
function getTests() {
http.open('get', 'rpc/tests/main.php?rand=' + Math.random() );
http.onreadystatechange = handleAdmin;
http.send(null);
}
function getUnlock() {
http.open('get', 'rpc/unlock.php?rand=' + Math.random());
http.onreadystatechange = handleAdmin;
http.send(null);
}
function getGrade() {
http.open('get', 'rpc/grade.php?rand=' + Math.random());
http.onreadystatechange = handleAdmin;
http.send(null);
}
function getActive() {
http.open('get', 'rpc/active.php?rand=' + Math.random());
http.onreadystatechange = handleAdmin;
http.send(null);
}
function handleAdmin() {
if (http.readystate == 4) {
document.getElementById('admin_box').innerHTML = http.responseText;
}
}
All of this works perfectly fine in IE6, but not in Firefox.
In firefox the buttons show up, but if you click any of them, nothing happens at all. An no errors show in the error console.
The thing that really bothers me about this is there is another part of my web site that works fine in firefox and it uses IDENTICAL javascript (with the exception of URLs of course).
If anyone could give me any guidance on this issue, I would be extremely grateful.
Thank you for your time
Last edited by PeejAvery; October 22nd, 2008 at 05:47 PM.
Reason: Added code tags
It's because you aren't creating your AJAX object correctly. Use the following instead.
Code:
var ro;
try {ro = new XMLHttpRequest();}
catch(e) {
try {ro = new ActiveXObject("Msxml2.XMLHTTP");}
catch(e) {
try {ro = new ActiveXObject("Microsoft.XMLHTTP");}
catch(e) {
alert("Your browser does not support AJAX!");
return false;
}
}
}
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
function createRequestObject() {
var ro;
try {ro = new XMLHttpRequest();}
catch(e) {
try {ro = new ActiveXObject("Msxml2.XMLHTTP");}
catch(e) {
try {ro = new ActiveXObject("Microsoft.XMLHTTP");}
catch(e) {
alert("Your browser does not support AJAX!");
return false;
}
}
}
}
var http = createRequestObject();
It does not work in IE 6 and firefox gave me an error that 'http has no properties'
this was because the function was not returning anything.
so i modified it to this:
Code:
function createRequestObject() {
var ro;
try {ro = new XMLHttpRequest();return ro;}
catch(e) {
try {ro = new ActiveXObject("Msxml2.XMLHTTP");return ro;}
catch(e) {
try {ro = new ActiveXObject("Microsoft.XMLHTTP");return ro;}
catch(e) {
alert("Your browser does not support AJAX!");
return false;
}
}
}
}
var http = createRequestObject();
Now, IE 6 works, but firefox still does nothing at all and gives no errors.
What am I doing wrong here?
Last edited by Nightwolf629; October 23rd, 2008 at 07:20 AM.
Reason: pasted wrong code
Well, you aren't returning the ro object. If there is no return, you can't set a variable equal to a function.
Code:
function createRequestObject() {
var ro;
try {ro = new XMLHttpRequest();}
catch(e) {
try {ro = new ActiveXObject("Msxml2.XMLHTTP");}
catch(e) {
try {ro = new ActiveXObject("Microsoft.XMLHTTP");}
catch(e) {
alert("Your browser does not support AJAX!");
return false;
}
}
}
return ro;
}
var http = createRequestObject();
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Bookmarks