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.
Ok, looks like the http request object is being created ok.
I proved this with the alerts, but I still have the same issue.
So i figure something else must be wrong with the rest of my javascript.
I got firebug (an addon for firefox), which I have never used before, but it looks like it is insanely helpful with scripting.
Anyways... in the firebug console, it receives and displays there result from the http request. At the same time, firefox still does not display it.
I had to change an option in firebug to "allow double post".
So it looks like this problem is being caused by some security feature on firefox. I don't know if I can disable it or not... but thats not the issue anyways, I don't want to require people to make changes to thier browser in order to use the webpage.
I know that firefox will not allow httprequest to access data from another domain... but im not sure if that has anything to do with this or not. Its not going to a different domain, its just going to a different directory on the server
Something else I just noticed when looking over your code again is that you are only creating one instance of AJAX for the whole page. I think you need to re-work your code so that there are not so many functions and so that there is a new AJAX instance created for each AJAX process.
Bookmarks