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