I have a form with two options, when onclick AJAX call to a php file which creates a temporary table with all possible results. So if the users select another option again it would load faster.
The problem is that the ajax call to the php file always creates and inserts the elements all over again, how can I avoid this?, how can I create the temporary table once.
is it possible to call the php file only once?
Sorry for the bad expression but I'm kinda new to PHP,AJAX, etc.
My ajax call:
<script type="text/javascript">
function showAliveData(str,str2){
if (str=="null" || str2=="null")
{
document.getElementById("resultados").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("resultados").innerHTML=xmlhttp.responseText;
$("#tablaResultados").tablesorter("update");
}
}
document.getElementById("resultados").innerHTML='<div id="loader">La conexión con Google Analytics puede tardar unos segundos, por favor espere..</div>';
xmlhttp.open("GET","test.php?seccion="+str+"&elemento="+str2,true);
xmlhttp.send();
}
</script>
HTML:
<form name="form">
<select name="seccion">
<option value="null" style="color:#D3D3D3" disabled="disabled" selected="selected">Sección</option>
<option value="Home">Home</option><br/>
<option value="Promociones">Promociones</option>
<option value="all">- Todas las secciones -</option>
</select>
<select name="elemento">
<option value="null" style="color:#D3D3D3" disabled="disabled" selected="selected">Elemento</option>
<option value="Vitrina">Vitrina</option><br/>
<option value="Banner">Banner</option>
<option value="Destinos destacados">Destinos destacados</option>
<option value="Box">Box</option>
<option value="all">- Todos los elementos -</option>
</select>
<input type="button" value="Alive" onclick="showAliveData(seccion.value,elemento.value)">
The PHP file:
Basically
-Creates the temporary table
-Inserts all data
-display the data the user selected
Thank you in advance!