Retroceder   Foros del Web > Programación para sitios web > AJAX
Crea un nuevo usuario o inicia sesión utilizando tu cuenta de Facebook
Connect with Facebook

Respuesta
 
Herramientas Desplegado
Antiguo 09-ene-2009, 04:01   #1 (permalink)
nanito85 ha deshabilitado el karma
 
Fecha de Ingreso: enero-2009
Mensajes: 7
nanito85 está desconectado
Actualizar o recargar fichero PHP con AJAX

Hola, os cuento mi problema

un boton tiene asociada una funcion en Ajax para insertar datos en una BD

EN dicha funcion se verifica una condicion, y si ocurre, se actualizan algunas tablas en la BD

Tras dicha actualizacion, me interesa que se vuelva a ejecutar el fichero php, con los nuevos valores, para mostrar un contenido distinto al anterior.

Para ello, debo usar Ajax


Este es un script en js que me han proprocionado, AjaxHelper.js,

Código:
function ajaxHelper(functionName, additionalArgs)
{
    var xmlHttp;

    // Firefox, Opera 8.0+, Safari, SeaMonkey
    try
    {
        xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e)
            {
                alert("Sorry, your browser does not support AJAX.");
                return false;
            }
        }
    }

    xmlHttp.onreadystatechange=function()
    {
        //The request is complete == state 4
        if (xmlHttp.readyState==4)
        {
            var response=xmlHttp.responseText;
            //Send reponse to _ajax hook of passed function name
            eval(functionName + "_ajax" + '(\'' + response + '\')');
        }
    }

    //Get request string from _setup hook of passed function name
    if (additionalArgs !== undefined && additionalArgs.length > 0)
    {
        var requestString = eval(functionName+"_init" + '(' + additionalArgs + ')');
    }
    else
    {
        var requestString = eval(functionName+"_init" + '()');
    }

    if (requestString)
    {
        xmlHttp.open("POST", requestString, true);
        xmlHttp.send(null);
        requestString = null;
    }
}
Luego en mi php, tengo los sigueintes scripts
Código:
<script language="JavaScript" type="text/javascript" src="AjaxHelper.js"></script>
<script language="javascript">
		function juego_ajax(results)
		{
			var targetDiv=document.getElementById('juego');
			targetDiv.innerHTML=results;
		}
        function juego_init()
        {
            return '/juegoini.php';
        }
        function onLoad()
        {
            ajaxHelper('juego');
           	var time = 1; //time in seconds
            var interval = time * 1000;
            var timer = setInterval("ajaxHelper('juego')", interval);
        }


</script>
Esto en concreto me da error, y no muestra bien el contenido del php

Alguna sugerencia?


El id=juego corresponde al id de un iframe llamado juegoini.php
  Responder Citando
Respuesta
No hay votos aún.

Herramientas
Desplegado

Normas de Publicación
No puedes crear nuevos temas
No puedes responder temas
No puedes subir archivos adjuntos
No puedes editar tus mensajes

BB code está Activado
Caritas están Activado
[IMG] está Activado
Código HTML está Desactivado
Trackbacks está Desactivado
Pingbacks está Desactivado
Refbacks está Desactivado



La zona horaria es GMT -6. Ahora son las 14:08.
Políticas de Uso de Foros del Web


Message Board Statistics

SEO by vBSEO 3.3.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100