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.