Retroceder   Foros del Web > Programación para sitios web > AJAX

Tema Cerrado
 
Herramientas Desplegado
Antiguo 13-sep-2007, 13:16   #1 (permalink)
maderic_m no se puede cailificar en este momento
 
Avatar de maderic_m
 
Fecha de Ingreso: agosto-2007
Mensajes: 45
Activar - Desactivar Checks

hola a todos, estoy trabajando en un proyecto en el cual tengo q activar noticias, con lo cual voy a usar xajax para cuando hago clic sobre el check de la noticia esta se active automaticamnte, osea q en la db el campo activo se pone en uno, pero el problema es que no puedo hacer andar nada, osea cargo el js con $xajax->getJavascript('./includes/xajax/');, pero cuando hago un clic sobre los check no pasa nada, no me muestra el msj q diga activado o desactivado, todo esto lo hago con un sistemas de plantillamas, a continuacion paso los codigos:

activar.php: en este archivo esta la funcion que activa la noticia.
Código:
<?php
// LO USO PARA DEFINAR LAS FUNCIONES QUE VOY A USAR CON AJAX

require("xajax_core/xajax.inc.php");
$xajax = new xajax();

/* Esta funcion activa o desactiva los productos */
function activar($id, $chec)
{
   // creo una istancia de una respuesta
    $resp = new xajaxResponse();
    // selecciono el prodcucto a activar
    if ($chec == "true") {      
        $resp->assign($id, "innerHTML", "Activado");
    } else{        
        $resp->assign($id, "innerHTML", "Desactivado");
    }
	
    return $resp;
}
/*****     fin activar    *****/

$xajax->registerFunction("activar");
$xajax->processRequest();
?>
xajax.php: este es el q levanta el template, asiganado a casa chek en el nombre osea en name="", asigno el id que saco de la db, y desp si la noticia ya esta activada pone el check activado.

Código:
<?php
include_once('./includes/conexion.php');
include_once('./includes/template.php');
include_once('./includes/xajax/activar.php');

//selecciono los elementos del listado
$prod = $conexion->Execute('SELECT * FROM productos');

$js = $xajax->getJavascript('./includes/xajax/');

//relleno el template
set_file('ajax1', 'ajax.html');

set_var('printjava', $js);
if ($prod->EOF)
	set_var('bloque', 'NO HAY PRODUCTOS A LISTAR');
while(!$prod->EOF){
	set_var('nom', $prod->fields['id']);
	set_var('nombre', $prod->fields['nombre']);
	if($prod->fields['activo'] == 1)
		set_var('check', ' checked="checked" ');
	else
		set_var('check', '');
	$prod->MoveNext();
	parse('bloque', 'bloque', true);
}
parse('general');
pparse('ajax1');
?>

xajax.html: este es el template html en el cual se insertan los contenidos de la db, capas el error esta en llamar a la funcion js, pero no se la idea es pasar en el primer parametro el atributo name="" q seria el id de la noticia y el segundo parametro es si esta activado o desactivado el check. El id del div en el cual se va a mostrar el msj es el mismo nombre del del chek q corresponde al id de la db, esto lo hago por q si pongo el mismo nombre a todos los div capas el msj de respuesta me cambia todo los div y no solo los del chec q active.

Código:
<!-- BEGIN general -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin t&iacute;tulo</title>
{printjava}
</head>

<body>

<table width="400" border="0" align="center">
  <tr>
    <td>&nbsp;</td>
    <td><div align="center">Prueba de AJAX</div></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><form id="form1" name="form1" method="post" action="">
      <table width="100%" border="0">
        <!-- BEGIN bloque -->
        <tr>
          <td>{nombre}</td>
          <td><div align="center">
              <label>
              <input name="{nom}" type="checkbox"  value="1"  {check} onchange="xajax_activar(document.form1.{nom}.name, document.form1.{nom}.checked);" />
              </label>
            <div id="{nom}"></div>
          </div></td>
        </tr>
        <!-- END bloque -->
      </table>
        </form>
    </td>
    <td>&nbsp;</td>
  </tr>
</table>

</body>
</html>
<!-- END general -->
codijo js: este es el codigo q imprime el metodo $xajax->getJavascript('./includes/xajax/');

Código:
<script type="text/javascript" charset="UTF-8">
/* <![CDATA[ */
try { if (undefined == xajax.config) xajax.config = {}; } catch (e) { xajax = {}; xajax.config = {}; };
xajax.config.requestURI = "http://localhost/ajax/ajax.php";
xajax.config.statusMessages = false;
xajax.config.waitCursor = true;
xajax.config.version = "xajax 0.5 Beta 4";
xajax.config.legacy = false;
xajax.config.defaultMode = "asynchronous";
xajax.config.defaultMethod = "POST";
/* ]]> */
</script>
<script type="text/javascript" src="./includes/xajax/xajax_js/xajax_core.js" charset="UTF-8"></script>
<script type="text/javascript" charset="UTF-8">
/* <![CDATA[ */
window.setTimeout(
 function() {
  var scriptExists = false;
  try { if (xajax.isLoaded) scriptExists = true; }
  catch (e) {}
  if (!scriptExists) {
   alert("Error: the xajax Javascript component could not be included. Perhaps the URL is incorrect?nURL: ./includes/xajax/xajax_js/xajax_core.js");
  }
 }, 2000);
/* ]]> */
</script>

<script type='text/javascript' charset='UTF-8'>
/* <![CDATA[ */
xajax_activar = function() { return xajax.request( { xjxfun: 'activar' }, { parameters: arguments } ); };
/* ]]> */
</script>

Codigo final: asi se vel el html final.
Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin t&iacute;tulo</title>

<script type="text/javascript" charset="UTF-8">
/* <![CDATA[ */
try { if (undefined == xajax.config) xajax.config = {}; } catch (e) { xajax = {}; xajax.config = {}; };
xajax.config.requestURI = "http://localhost/ajax/ajax.php";
xajax.config.statusMessages = false;
xajax.config.waitCursor = true;
xajax.config.version = "xajax 0.5 Beta 4";
xajax.config.legacy = false;
xajax.config.defaultMode = "asynchronous";
xajax.config.defaultMethod = "POST";
/* ]]> */
</script>
<script type="text/javascript" src="./includes/xajax/xajax_js/xajax_core.js" charset="UTF-8"></script>
<script type="text/javascript" charset="UTF-8">
/* <![CDATA[ */
window.setTimeout(
 function() {
  var scriptExists = false;
  try { if (xajax.isLoaded) scriptExists = true; }
  catch (e) {}
  if (!scriptExists) {
   alert("Error: the xajax Javascript component could not be included. Perhaps the URL is incorrect?nURL: ./includes/xajax/xajax_js/xajax_core.js");
  }
 }, 2000);
/* ]]> */
</script>

<script type='text/javascript' charset='UTF-8'>
/* <![CDATA[ */
xajax_activar = function() { return xajax.request( { xjxfun: 'activar' }, { parameters: arguments } ); };
/* ]]> */
</script>

</head>

<body>

<table width="400" border="0" align="center">
  <tr>
    <td>&nbsp;</td>
    <td><div align="center">Prueba de AJAX</div></td>
    <td>&nbsp;</td>
  </tr>

  <tr>
    <td>&nbsp;</td>
    <td><form id="form1" name="form1" method="post" action="">
      <table width="100%" border="0">
        
        <tr>
          <td>Casa</td>
          <td><div align="center">
              <label>

              <input name="1" type="checkbox"  value="1"   onchange="xajax_activar(document.form1.1.name, document.form1.1.checked);" />
              </label>
            <div id="1"></div>
          </div></td>
        </tr>
        
        <tr>
          <td>Dpto</td>
          <td><div align="center">

              <label>
              <input name="2" type="checkbox"  value="1"   checked="checked"  onchange="xajax_activar(document.form1.2.name, document.form1.2.checked);" />
              </label>
            <div id="2"></div>
          </div></td>
        </tr>
        
        <tr>
          <td>Terreno</td>

          <td><div align="center">
              <label>
              <input name="3" type="checkbox"  value="1"   onchange="xajax_activar(document.form1.3.name, document.form1.3.checked);" />
              </label>
            <div id="3"></div>
          </div></td>
        </tr>
        
      </table>
        </form>

    </td>
    <td>&nbsp;</td>
  </tr>
</table>

</body>
</html>
si a alguien se le ocurre una idea para ayudarme se lo agradeceria, saludos.
maderic_m está desconectado  
Tema Cerrado
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 is Activado
Caritas están Activado
[IMG] está Activado
Código HTML está Desactivado


La Zona horaria es GMT -6. Ahora son las 04:23.


Message Board Statistics

LinkBacks Enabled by vBSEO 3.1.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