Foros del Web » Programando para Internet » Javascript » Frameworks JS »

new net.CargadorContenidos

Estas en el tema de new net.CargadorContenidos en el foro de Frameworks JS en Foros del Web. Hola, Estoy realizando mi primer ejercicio y no obtengo la respuesta esperada. Mi codigo es este: El fichero ejercicio1a.php Código HTML: <html> <head> <script language= ...
  #1 (permalink)  
Antiguo 10/10/2011, 12:24
 
Fecha de Ingreso: septiembre-2006
Mensajes: 114
Antigüedad: 17 años, 7 meses
Puntos: 1
new net.CargadorContenidos

Hola,

Estoy realizando mi primer ejercicio y no obtengo la respuesta esperada.
Mi codigo es este:

El fichero ejercicio1a.php

Código HTML:
<html>
<head>
<script language="javascript" src="./ajax.js" type=text/javascript></script>
<script type="text/javascript">
    //Validacion de numero
    function isNumero(num){
        if(/^([0-9])*$/.test(num)) {
            return true;
        }else{
            return false;
        }
    }

    function cargarTablaMultiplicar() {
        var form = document.getElementById('formularioMultiplicar');
        var numero =  form.numero.value;
        if(numero!='' && isNumero(numero)){
            var url ='<?php echo $HTTP_REFERER ?>' +'tablaMultiplicarAjax.php?numero='+numero;
            //"application/x-www-form-urlencoded"
            new net.CargadorContenidos (url, muestraContenido, null, 'GET', null,null);
        }else{
            alert('Debe introducir un numero');
        }
        
    }

    function muestraContenido   () {
        var divTabla = document.getElementById('tablaMultiplicar');
        divTabla.innerHTML = this.req.responseText;
    }
El fichero ajax.js

Código HTML:
var net = new Object();

net.READY_STATE_UNINITIALIZED=0;
net.READY_STATE_LOADING=1;
net.READY_STATE_LOADED=2;
net.READY_STATE_INTERACTIVE=3;
net.READY_STATE_COMPLETE=4;

// Constructor
net.CargadorContenidos = function(url, funcion, funcionError, metodo, parametros,contentType) {
    this.url = url;
    this.req = null;
    this.onload = funcion;
    this.onerror = (funcionError) ? funcionError : this.defaultError;
    this.cargaContenidoXML(url, metodo, parametros, contentType);
};

net.CargadorContenidos.prototype = {
    cargaContenidoXML: function(url, metodo, parametros, contentType) {
        if(window.XMLHttpRequest) {
            this.req = new XMLHttpRequest();
        }else if(window.ActiveXObject) {
            this.req = new ActiveXObject("Microsoft.XMLHTTP");
        }
        if(this.req) {
            try {
                var loader = this;
                this.req.onreadystatechange = function() {
                    loader.onReadyState.call(loader);
                };
                this.req.open(metodo, url, true);
                if(contentType) {
                    this.req.setRequestHeader("Content-Type", contentType);
                }
                this.req.send(parametros);
            } catch(err) {
                this.onerror.call(this);
            }
        }
    },
    onReadyState: function() {
        var req = this.req;
        var ready = req.readyState;
        if(ready == net.READY_STATE_COMPLETE) {
            var httpStatus = req.status;
            if(httpStatus == 200 || httpStatus == 0) {
                this.onload.call(this);
            }
            else {
                this.onerror.call(this);
            }
        }
    },
    defaultError: function() {
        alert("Se ha producido un error al obtener los datos"
                + "\n\nreadyState:" + this.req.readyState
                + "\nstatus: " + this.req.status
                + "\nheaders: " + this.req.getAllResponseHeaders());
    }
};
Y el fichero de recarga tablaMultiplicarAjax.php


Código HTML:
<center>
<?php
$metodo=$_SERVER['REQUEST_METHOD'];
echo "<h2>Tabla del $_GET[numero] </h2>";
for($i=1;$i<=10;$i++){
$resultado=$i*$_GET[numero];
echo "<b>$_GET[numero] x $i = $resultado</b></br>";
}
?>
</center> 
Me esta falladando en esta línea this.req.send(parametros); pero no llego a entender porque.

Gracias

Etiquetas: ajax, funcion, html, javascript, js, php
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:31.