I create dependent select dropdown as https://github.com/phalcon/cphalcon/wiki/Dependent-Select-Dropdown
But When I call ajax, return a whole page. ajax link is eg. "inform/search" like that. but it respond whole page. Can you suggect for me?
|  | Nov '15 | 5 | 504 | 0 | 
I create dependent select dropdown as https://github.com/phalcon/cphalcon/wiki/Dependent-Select-Dropdown
But When I call ajax, return a whole page. ajax link is eg. "inform/search" like that. but it respond whole page. Can you suggect for me?
Hi,
with ajax action set in controller the view component to LEVEL_NO_RENDER:
https://docs.phalcon.io/en/latest/reference/views.html#control-rendering-levels
Hi Bryan,
I already used as you say but it return whole page as follow.
if you want to return something from controller into ajax, a simple
echo json_encode(//whatever you want);will do.If it is a bug you encountering with ajax, try
console.log();to see what is being returned.
Hi, I think you can follow @le51 suggestion by doing:
$this->view->disable(); in your controller function at the start.
Hi Bryan,
I already used as you say but it return whole page as follow.
if you want to return something from controller into ajax, a simple
echo json_encode(//whatever you want);will do.If it is a bug you encountering with ajax, try
console.log();to see what is being returned.
Thanks Bryan & le51. Now I'm done.
In Volt
<div class="col-xs-2">
    {{ select("countrycode", countries, "using":['countrycode','name'], "useEmpty":false, "class":"form-control") }}                  
</div>
<div class="col-xs-2">
    {{ select("state", dis, "using":['stateId','name'], "useEmpty":false, "class":"form-control") }}
</div>
In Javascript
$("#countrycode").change(function(event){
  var value = $(this).val();
  var getResultsUrl = 'inform/search';          
  $.ajax({
    type: "POST",
    url: getResultsUrl,
    data: {"countrycode": value},
    success: function(response){                    
      $("#state").empty();
      parsed = $.parseJSON(response);
        $.each(parsed, function(){
           $("#state").append('<option value="'+ this.stateId +'">'+ this.name +'</option>');
        });                 
      }
    });
  });In Controller
public function searchAction()
 {
    $countrycode= $this->request->getPost("countrycode","int"); 
    $query = "SELECT * FROM state WHERE state.countrycode=$countrycode";                
    $result_dis = $this->modelsManager->executeQuery($query);
    $resData = array();
    foreach ($result_dis as $result) {
            $resData[]= array("stateId"=>$result->stateId, "name"=>$result->name);
        }
    echo json_encode($resData);
    exit;   
 }