Web Analytics Made Easy -
StatCounter AJAX IE error - CodingForum

Announcement

Collapse
No announcement yet.

AJAX IE error

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • AJAX IE error

    I have an ajax code that works fine in firefox, but not in IE. The bit of code we're interested in is:
    Code:
    <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...
    Code:
    <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:
    Code:
    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

  • #2
    I cant say i see anything wrong with it.
    but i can say that I.E. doesnt like to let you POST. it is a security thing.
    I'm asumming you have I.E. right? try saving the file as a .hta file, i'll bet it works then. but of course that is not a solution to your problem. it is only a means to prove that the code works for i.e. when higer privliges are granted. (.hta is a hyper text application).
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.

    Comment


    • #3
      You can post in AJAX just fine in IE. Below is some example code. Are you sure the page you are requesting is on the same domain?

      Code:
      function getReqObjPost(url,params,func)
      {
      	if (window.XMLHttpRequest)
        	{
       		xmlhttp=new XMLHttpRequest();
       	}
       	else if (window.ActiveXObject)
          {
          	if(new ActiveXObject("Microsoft.XMLHTTP"))
          	{
          		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
          	}
          	else
          	{
          		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
          	}
          }
        	
        	xmlhttp.onreadystatechange=function()
        	{
        		if(xmlhttp.readyState==4)
      		{	
      			if(xmlhttp.status==200)
      			{
      				var req_str=xmlhttp.responseText;
      				var req=xmlhttp.responseXML;
      				eval(func);
      			}
      			else
      			{
      				noData(xmlhttp.status);	
      			}
      		}
        	}
      	var now=new Date();
      	params=params + "&c_date"+now.getSeconds()+"=" + now;
      	xmlhttp.open("POST",url,true);
      	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
      	xmlhttp.send(params);
      }
      Call like this:
      Code:
      getReqObjPost("somepage.asp","x=y&c=b&red=pretty","someCallBackFunction(req,req_str)")
      Basscyst
      Helping to build a bigger box. - Adam Matthews

      Comment


      • #4
        It is possible that IE prevents you from using scripts to open files on your computer; also products like defender and antispy may be overprotecting you. If it works in firefox, and you don't get a null object error in IE, then the code is OK. Look to your security settings.

        Comment


        • #5
          Originally posted by brandonH View Post
          I cant say i see anything wrong with it.
          but i can say that I.E. doesnt like to let you POST. it is a security thing.
          I'm asumming you have I.E. right? try saving the file as a .hta file, i'll bet it works then. but of course that is not a solution to your problem. it is only a means to prove that the code works for i.e. when higer privliges are granted. (.hta is a hyper text application).
          As a .hta file I get the same error

          Comment

          Working...
          X