0

When i click selectbox than i want to alert data.But it not working.what is the wrong in ajaxcalling.pls help

<?php
echo $this->Form->create('Office');
echo $this->Form->input('office_type', array('type' => 'select', 'id' =>'office_type_id','options' => $settings1,'empty'   => false));
echo $this->Form->end('Save');
?>

<script type="text/javascript">

    $("#office_type_id").change(function() {   
    var office_type_id=$('#office_type_id').val(); 

    $.ajax({
          url     : "<?php echo Router::url(array('controller' => 'Offices', 'action' =>'getoffices'), true); ?>",
          type    : "POST",
          cache   : false,
          data    : {office_type_id: office_type_id},
          alert(data);
          success : function(data){

          }
      });
    });
</script>

2 Answers 2

1

This answer is not relevant to the original question but I am leaving this here for others who may find this question looking for the same solution I did - essentially, my AJAX requests were lost and were never reaching my controller methods. It had me baffled for a few hours until I realized that I had Cake Authentication & Authorization active. Hence, I needed to allow access using the beforeFilter method. Use the following snippet to ensure your AJAX calls do reach your controller methods if you are using CAKE authentication / Authorization

/*
 * beforeFilter method
 *
 * @return void
 */ 
    public function beforeFilter() {
        parent::beforeFilter();
        $this->Auth->allow();
    }
Sign up to request clarification or add additional context in comments.

1 Comment

I had the same problem with 'Security'.
0

Remove alert before success:

$("#office_type_id").change(function() {   
    var office_type_id=$('#office_type_id').val(); 

    $.ajax({
          url     : "<?php echo Router::url(array('controller' => 'topics', 'action' =>'test'), true); ?>",
          type    : "POST",
          cache   : false,
          data    : {office_type_id: office_type_id},
          success : function(data){
                  alert(data);
          }
      });
    });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.