Page 1 of 1

A lil' bit AJAX

Posted: Wed Aug 09, 2006 2:25 pm
by peperoni
Hi,

i been trying AJAX just a little bit but i got this rare error!

My code:

Code: Select all

<html>
   <head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
   <title>Ajax en el Trabajo</title>
   <script language=JavaScript>
	var XMLHttpRequestObjeto = false;
	if(window.XMLHttpRequest){
	   XMLHttpRequestObjeto = new XMLHttpRequest();
	}
	else if(window.ActiveXObject){
	   XMLHttpRequestObjeto = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
   function getData(dataSource, DivId){
   if(XMLHttpRequestObjeto){
   var obj = document.getElementById(DivId);
   XMLHttpRequestObjeto.open("GET", dataSource);
   XMLHttpRequestObjeto.onreadystatechange = function(){
      if(XMLHttpRequestObjeto.readyState==4 && XMLHttpRequestObjeto.status == 200){
         obj.innerHTML = XMLHttpRequestObjeto.responseText;
      }
   }
   XMLHttpRequestObjeto.send(null);
   }
   }
   </script>
   </head>
   <body>
   <h1>Poniendo la fecha con AJAX</h1>
   <form>
   <input type=button value="Ver Mensaje!" onclick="(getData('http://192.168.100.107/pruebas/cap3/dd.txt'),'divId')">
   </form>
   <div id=divId>
   <p>La info capturada va aca!</p>
   </div>
   </body>
</html>
dd.txt

Code: Select all

Hello World!
The error:
uncaught exception: Permiso denegado al llamar al método XMLHttpRequest.open
????

C ya!

Posted: Wed Aug 09, 2006 2:41 pm
by Buddha443556

Posted: Wed Aug 09, 2006 3:00 pm
by peperoni
It's a local file!

But i didnt understand totally what
you need to tell Mozilla/Firefox about that
means :(

Posted: Wed Aug 09, 2006 3:18 pm
by peperoni
i think could be this way, callin trought another page

Code: Select all

ObjHTTP.open("GET", geturl?url=dataSource)
C ya!

Posted: Wed Aug 09, 2006 3:26 pm
by Buddha443556
peperoni wrote:It's a local file!

But i didnt understand totally what
you need to tell Mozilla/Firefox about that
means :(
You are using Firefox (or something Netscape like) correct? Anyway ...

Code: Select all

try {
    netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
   } catch (e) {
    alert("Permission UniversalBrowserRead denied.");
   }
That snippet should ask Firefox for permission. Firefox should then popup a dialog box asking you to give permission.

Posted: Wed Aug 09, 2006 3:39 pm
by peperoni
Both IE and Firefox... doesnt work! :(
Permission UniversalBrowserRead denied.
:?

Posted: Wed Aug 09, 2006 3:52 pm
by Christopher
EDIT - The error is in the onChange javascript. It should be:

Code: Select all

<form>
   <input type=button value="Ver Mensaje!" onclick="getData('http://server1/dd.txt','divId');">
   </form>
   <div id="divId">
   <p>La info capturada va aca!</p>
   </div>

Posted: Wed Aug 09, 2006 4:05 pm
by peperoni

Posted: Wed Aug 09, 2006 4:17 pm
by peperoni
arborint wrote:EDIT - The error is in the onChange javascript. It should be:

Code: Select all

<form>
   <input type=button value="Ver Mensaje!" onclick="getData('http://server1/dd.txt','divId');">
   </form>
   <div id="divId">
   <p>La info capturada va aca!</p>
   </div>
Yeah, right! I just added semicolom at the end of the OnClick :D but i got no changes in my page, a part of the code its not workin'

Code: Select all

if(XMLHttpRequestObjeto.readyState==4 && XMLHttpRequestObjeto.status == 200){
   obj.innerHTML = XMLHttpRequestObjeto.responseText;
}

Posted: Wed Aug 09, 2006 4:58 pm
by nickvd
I might be wrong about this, but i'll try anyway... As far as I can remember, the xmlhttp request must be made to the same server that the call came from. So if you are using it from a page located at http://localhost/ajax.html then the request must go to http://localhost/server.php ... the following (although equal from a networking standpoint) wont (shouldnt) work: http://127.0.0.1/server.php or http://192.168.1.100 (assuming .100 is localhost)... so try modifying the requst url and report back what happens...

Posted: Wed Aug 09, 2006 5:05 pm
by Christopher
peperoni wrote:Yeah, right! I just added semicolom at the end of the OnClick :D but i got no changes in my page, a part of the code its not workin'
It was not the semicolon, it was your wacky parens:

Code: Select all

onclick="(getData('http://192.168.100.107/pruebas/cap3/dd.txt'),'divId')"
I got the code to work fine.