Search code examples
jquerysymfony1symfony-1.4symfony-forms

Request ajax with html response - Symfony 1.4


I want to make an ajax request by a method that returns a html in Symfony 1.4. All ok but I get an error parse json jquery and nowhere to get a specific treatment or parse json response.

ERROR ERROR

Code In view consultas.php (template module remision)

<html>
...
<div id="results"> </div>
...
<html>
....
<script>
  function Consultar(){
     var form = $("#remisiones_filter");

     $.ajax({
         url:form.attr("action"),  //actions.class.php => method executeAjaxProcessFilter
         data: form.serialize(),
         contentType: 'text/html',
         type:'GET',
         dataType: 'html',
             success: function(result){
                 $('#results').html(result);
             }
     });

     $('#results').fadeIn();
     return false;
     }

 </script>

The php actions.class.php (actions module remision)

public function executeAjaxProcessFilter($request) {
    $this->setLayout(false);   //NO LAYOUT

        $data = "lalala";

        $this->setVar('data',$data);
        $this->setVar('showMatriculas',$showMatriculas);
        /**1**/
      }else
          $this->setVar('data',"error de filtro");

    }
      $this->setVar('data',"Vacio");
  }

And the view code html respond AjaxProcessFilterSuccess.php (template module remision)

<div>
<?php print_r($data); ?>
</div>

/**1**/ if respond with return $this->renderText("lala"), return is OK and the error does not appear.


Solution

  • for your variable $data to be accessible in the template it should be defined as

    $this->data = 'lalala'; in the action..

    Alternatively if data as sent as a request variable , you can echo $sf_params->get('data');