// Crea el objecto xmlhttp function creaAjax() { var xmlhttp = false; try { // versión de JavaScript superior a la 5 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { // objecto tradicional ActiveX if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else if(window.ActiveXObject) { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlhttp; } // Procesa un XMLHttpRequest // IdObj: debe ser o
// response: XML o Texto (html) // method: GET o POST // str: string de valores que se enviarán por POST (var=valor&var2=valor2...) function processAjax(URL,IdObj,response,method,str,funcion) { xmlhttp = creaAjax(); xmlhttp.open(method, URL); if (method == "POST") { // Añadimos un par etiqueta/valor al encabezado en el momento de enviarlo xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); xmlhttp.setRequestHeader("Content-length", params.length); xmlhttp.setRequestHeader("Connection", "close"); } xmlhttp.onreadystatechange = function() { // readyState = estado actual del objecto, status = respuesta del servidor if (xmlhttp.readyState==1) { $("#contenidos").animate({ height: 'hide', opacity: 'hide' }, 'fast'); //document.getElementById(IdObj).innerHTML = "


  Cargando...

"; //document.getElementById(IdObj).style.background = "url('/images/basic/loading.gif') no-repeat center"; } else if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { if (response == "XML") { document.getElementById(IdObj).innerHTML = xmlhttp.responseXML; } else { document.getElementById(IdObj).innerHTML = xmlhttp.responseText; } if (funcion) eval(funcion); $("#contenidos").animate({ height: 'show', opacity: 'show' }, 'fast'); //document.getElementById(IdObj).style.background = ""; } } if (method == "GET") { xmlhttp.send(null); } else { xmlhttp.send(str); } } // Comprueba si existe un objecto function chkObject(inParent,theVal) { if (inParent) { if (window.opener.document.getElementById(theVal) != null) return true; else return false; } else { if (document.getElementById(theVal) != null) return true; else return false; } }