Ver Mensaje Individual
  #5 (permalink)  
Antiguo 25/07/2013, 11:18
mandygr87
 
Fecha de Ingreso: abril-2013
Mensajes: 82
Antigüedad: 11 años
Puntos: 0
Respuesta: llamar a action desde javascript en la vista

¿¿Quedaría algo así?? No tengo apenas idea de javascript ni de ajax...

En mi vista:

Código Javascript:
Ver original
  1. <head>
  2.     <script language="Javascript">
  3.  
  4.     function validateForm()
  5.   {
  6.           var ajax = $.ajax({
  7.              type: "GET",
  8.              url: "/asociacion/public/cliente/bdusuarios/fechaentrada/" + <?php echo $this->fechaentrada?>+"/fechasalida/"+<?php echo $this->fechasalida?>+"/idbungalow/"+ <?php echo $this->idbungalow?>+"/idcamping/"+ <?php echo $this->idcamping?>+"/fechahoy/"+ <?php echo $this->fechahoy?>,
  9.              async: true,
  10.              dataType: "json",
  11.              beforeSend: function(x) {
  12.                 if(x && x.overrideMimeType) {
  13.                    x.overrideMimeType("application/j-son;charset=UTF-8");
  14.                 }
  15.              },
  16.              success: function(data){
  17.                 if(data=="true"){
  18.                     alert('Lo sentimos ya han realizado la reserva con los criterios seleccionados');
  19.                          event.preventDefault();
  20.                          return false;
  21.                 }    
  22.              }
  23.         });
  24.   }
  25.  
  26. </script>
  27. </head>
  28.  
  29. <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" onsubmit="return validateForm();" method="post"  >

En mi controlador:

Código PHP:
public function bdusuariosAction()
    {
        
$reserva = new Application_Model_DbTable_Reserva();
        
$fechaentrada$this->_getParam('fechaentrada');
        
$fechasalida$this->_getParam('fechasalida');
        
$idbungalow$this->_getParam('idbungalow');
        
$idcamping$this->_getParam('idcamping');
        
$fechahoy$this->_getParam('fechahoy');

        
$yahayreserva $reserva->comprobarreservabungalow($fechaentrada$fechasalida$idbungalow$idcamping$fechahoy);
        
$result false;
        if(
count($yahayreserva)>0){
            
$result true;
        }
        
$this->_helper->json($result);
    } 

Lo que quiero es pasar una variable booleana y que javascript la compruebe.
si es true no quiero que se realize el action del form, y si es false sí que quiero que se realice el action.

Gracias por la ayuda.