We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Action runs twice after Ajax callback

Hi there,

I'm calling back via AJAX to a controller/action to have it render some markup that I want to inject into the DOM in the Ajax success handler. My code appears to work fine except that it executes twice? I suspect I am doing something wrong but if anyone has any ideas as to what that might be, I'd appreciate it! :)

  public function priceTablesAction()
    if ($this->request->isPost() && $this->request->isAjax()) {


      $package_id = intval($this->request->getPost('package_id', 'int'));
      $booking_date = $this->request->getPost('booking_date', 'string');
      $booking_date_int = strtotime(str_replace('/', '-', $booking_date));
      $form = new PackageDateForm($this->session_booking_data->packages->value);


      $this->view->setVar('form', $form);
      $this->view->setVar('package_id', $package_id);
      $this->view->setVar('booking_date_int', $booking_date_int);
      $this->view->render('booking', 'priceTables');

      $markup = $this->view->getContent();


      echo json_encode($markup);

My callback code is really simple:

            $.post('booking/priceTables', { 'booking_date' : booking_date, 'package_id' : package_id },
                function(data) {
                  // Do something here ...



I'm happy to say that this is not a Phalcon issue. The onChangeDateTime event in the datetimepicker (http://xdsoft.net/jqplugins/datetimepicker/) was firing twice! Phalcon was simply following instructions! :)

Phalcon is really awesome!!