yonni
09-27-2006, 11:39 PM
I have an ajax code that works fine in firefox, but not in IE. The bit of code we're interested in is:
<a href=# onclick='view("ajaxpage","news.html","newsButton","news");'><img src="News2.gif" border="0" style="position: absolute; top: 118px; left: 605px;" name="newsButton"></a>
then...
<script type=text/javascript language=javascript>
var homePage="true";
var sessionsPage="false";
var montessoriPage="false";
var contactPage="false";
var ajaxPage="false";
var page;
function view(page,url,button,buttonimg) {
document.getElementById(page).style.visibility='visible';
if(page=="") {
return
}
ajaxPage="false";
if(page=="ajaxpage") {
ajaxPage="true";
document[button].src=buttonimg+'.gif';
document.getElementById("ajaxpage").style.visibility="visible";
http=getHTTPObject();
if(http==null) {
document.getElementById('ajaxpage').innerHTML="<img src='error.jpg'>Your browser does not support the scripts for this page";
return;
}
http.open("POST",url,true);
http.onreadystatechange = loadDocument;
http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http.send("firefoxfix=true");
} else {
document.getElementById("ajaxpage").style.visibility="hidden";
document["newsButton"].src='news2.gif';
}
}
function loadDocument() {
if (http.readyState==4 || http.readyState=="complete") {
document.getElementById("ajaxpage").innerHTML = http.responseText
}
}
function getHTTPObject() {
var objXMLHttp=null
if (window.XMLHttpRequest) {
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject) {
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}
</script>
This works lovely until the line:
http.open("POST",url,true);
Where IE enjoys to spit me an error message: "Access denied". The only explanation I can find for this is that I've requested it to open a file it isn't allowed to, which I havent. I am currently still testing this on my home PC (not a server yet), and the file I've requested it to open is (as you can see) in the same folder as this file.
I really don't get why this doesn't work, so I thought I'd let you guys have a look, cause having an extra pair of eyes that hasn't coded this from scratch always helps. Thanks in advance :)
<a href=# onclick='view("ajaxpage","news.html","newsButton","news");'><img src="News2.gif" border="0" style="position: absolute; top: 118px; left: 605px;" name="newsButton"></a>
then...
<script type=text/javascript language=javascript>
var homePage="true";
var sessionsPage="false";
var montessoriPage="false";
var contactPage="false";
var ajaxPage="false";
var page;
function view(page,url,button,buttonimg) {
document.getElementById(page).style.visibility='visible';
if(page=="") {
return
}
ajaxPage="false";
if(page=="ajaxpage") {
ajaxPage="true";
document[button].src=buttonimg+'.gif';
document.getElementById("ajaxpage").style.visibility="visible";
http=getHTTPObject();
if(http==null) {
document.getElementById('ajaxpage').innerHTML="<img src='error.jpg'>Your browser does not support the scripts for this page";
return;
}
http.open("POST",url,true);
http.onreadystatechange = loadDocument;
http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http.send("firefoxfix=true");
} else {
document.getElementById("ajaxpage").style.visibility="hidden";
document["newsButton"].src='news2.gif';
}
}
function loadDocument() {
if (http.readyState==4 || http.readyState=="complete") {
document.getElementById("ajaxpage").innerHTML = http.responseText
}
}
function getHTTPObject() {
var objXMLHttp=null
if (window.XMLHttpRequest) {
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject) {
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}
</script>
This works lovely until the line:
http.open("POST",url,true);
Where IE enjoys to spit me an error message: "Access denied". The only explanation I can find for this is that I've requested it to open a file it isn't allowed to, which I havent. I am currently still testing this on my home PC (not a server yet), and the file I've requested it to open is (as you can see) in the same folder as this file.
I really don't get why this doesn't work, so I thought I'd let you guys have a look, cause having an extra pair of eyes that hasn't coded this from scratch always helps. Thanks in advance :)