Comunidad de diseño web y desarrollo en internet online

Problema que no puedo solucionar.

Citar            
MensajeEscrito el 16 Nov 2007 06:49 pm
Hola que tal, pues al grano. Tengo el sisguiente codigo:

ajax.js

Código :

Ajax = {}

Ajax.makeRequest = function(method, url, callbackMethod){
   this.request = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Msxml2.XMLHTTP");
   this.request.onreadystatechange = callbackMethod;
   this.request.open = (method, url, true);
   this.request.send(url);
}

Ajax.checkReadyState = function(_id){
   _id = documnet.getElementById(_id);
   switch(this.request.readyState){
      case 1:
         _id.innerHTML = "Loading..."
         break
      case 2:
         _id.innerHTML = "Loading..."
         break
      case 3:
         _id.innerHTML = "Loading..."
         break
      case 4:
         AjaxUpdater.isUpdating = false;
         _id = "";
         return true;
   }
}

Ajax.getResponse = function(){
   if(this.request.getResponseHeader('Content-Type').indexOf('xml') != -1){
      return this.request.responseXML.documentElement;
   }else{
      return this.request.responseText;
   }
}



ajaxUpdater.js

Código :

AjaxUpdater = {};

AjaxUpdater.initialize = function(){
   AjaxUpdater.isUpdating = false;
}
AjaxUpdater.initialize();

AjaxUpdater.update = function(method, service, callback){
   if(callback == undefined || callback == ""){
      callback = AjaxUpdater.onResponse;
   }
   Ajax.makeRequest(method, service, callback);
   AjaxUpdater.isUpdating = true;
}

AjaxUpdater.onResponse = function(){
   if(Ajax.checkReadyState('loading') == true){
      AjaxUpdater.isUpdating = false;
   }
}



Index.html

Código :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es">
<head>
   <meta http-equiv="content-type" content="text/html; charset=utf-8" />
   <title>The response</title>
   <!--<script type="text/javascript" src="javascript/Utilities.js"></script> n/-->
   <script type="text/javascript" src="javascript/ajaxUpdater.js"></script>
   <!--<script type="text/javascript" src="javascript/HTTP.js"></script> /-->
   <script type="text/javascript" src="javascript/ajax.js"></script>
   <!--<link href="css/layout.css" rel="stylesheet" type="text/css" /> -->
   <script type="text/javascript">
      function initialize(){
         AjaxUpdater.update("GET","services/email.xml", onResponse);
      }
      function onResponse(){
         if(Ajax.checkReadyState('loading') == true){
            //parse here
            var categories = Ajax.getResponse().getElementsByTagName('category');
            for(var i=0; i<cathegories.length; i++){
               document.getElementById('body').innerHTML += Ajax.getResponse().getElementsByTagName('category')[i].firstChild.data + "<br />";
            }
         }
      }
      
function errorHandler(message, url, line)
{
    var errorMessage = "Error: "+ message +"\n";
    errorMessage += "URL: "+ url +"\n";
    errorMessage += "Line Number: "+ line +"\n";
    alert(errorMessage);
    return true;
}
onerror = errorHandler;
   </script>
   
</head>
<body onload="initialize()">
   <div id="loading">.</div>
   <div id="body">.</div>
</body>
</html>



Cuando abro index.html me tira un herror que no entiendo y que no se como solucionar. Eh tratado de muchas maneras y no se soluciona. Este es el herror:


Error: uncaught exception: [Exception... "Component returned failure code: 0xc1f30001 (NS_ERROR_NOT_INITIALIZED) [nsIXMLHttpRequest.send]" nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)" location: "JS frame :: file://localhost/Users/panzaindigestadita/Sites/practicaajax/segundo/javascript/ajax.js :: anonymous :: line 7" data: no] URL: Line Number: 0

(el herro que tira es lo que esta en marron, lo demas lo agraro cuando hago el debug.

Alguien sabe como puedo solucionar ese problema?
Estoy usando firefox para hacer las pruevas pero ya trate en safari y

Gracias.

Por buzu

163 de clabLevel



 

Los Angeles, California

firefox
Citar            
MensajeEscrito el 19 Nov 2007 07:35 pm
Lo que pasa es q no nodiferencias si los datos los queres enviar por post o por get... creo q por ahi anda el problema

Código :


Ajax = {}

Ajax.makeRequest = function(method, url, callbackMethod){
   this.request = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Msxml2.XMLHTTP");
   this.request.onreadystatechange = callbackMethod;
   if(method.toUpperCase()  == "POST"){
        this.request.open(method.toUpperCase(), url);
        this.request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
   this.request.send(datos); 
   }else{
   url = url+'?'+datos;
   this.request.open(method.toUpperCase(), url, true);
   this.request.send(null); 
   }
}

.....



donde la variable datos tiene el queryString que vas a enviar


Saludos

Por 3w

145 de clabLevel



Genero:Masculino  

firefox
Citar            
MensajeEscrito el 24 Feb 2009 06:29 pm
La funcion makeRequest te devolverá un objeto estilo

{
data:
error:
text:
}

con el contenido de text.xml que luego se podrá procesar por otra parte?

Por dablin

0 de clabLevel



 

msie7

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.