A lil' bit AJAX

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
peperoni
Forum Newbie
Posts: 16
Joined: Thu Jun 15, 2006 10:52 pm
Location: Managua, Nicaragua
Contact:

A lil' bit AJAX

Post 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!
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

User avatar
peperoni
Forum Newbie
Posts: 16
Joined: Thu Jun 15, 2006 10:52 pm
Location: Managua, Nicaragua
Contact:

Post by peperoni »

It's a local file!

But i didnt understand totally what
you need to tell Mozilla/Firefox about that
means :(
User avatar
peperoni
Forum Newbie
Posts: 16
Joined: Thu Jun 15, 2006 10:52 pm
Location: Managua, Nicaragua
Contact:

Post by peperoni »

i think could be this way, callin trought another page

Code: Select all

ObjHTTP.open("GET", geturl?url=dataSource)
C ya!
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post 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.
User avatar
peperoni
Forum Newbie
Posts: 16
Joined: Thu Jun 15, 2006 10:52 pm
Location: Managua, Nicaragua
Contact:

Post by peperoni »

Both IE and Firefox... doesnt work! :(
Permission UniversalBrowserRead denied.
:?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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>
Last edited by Christopher on Wed Aug 09, 2006 4:06 pm, edited 1 time in total.
(#10850)
User avatar
peperoni
Forum Newbie
Posts: 16
Joined: Thu Jun 15, 2006 10:52 pm
Location: Managua, Nicaragua
Contact:

Post by peperoni »

User avatar
peperoni
Forum Newbie
Posts: 16
Joined: Thu Jun 15, 2006 10:52 pm
Location: Managua, Nicaragua
Contact:

Post 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;
}
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post 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...
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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.
(#10850)
Post Reply