Haris
Haris

Reputation: 372

ajax call not working in cakephp

I am trying to submit a form by ajax call.

 echo $this->Form->create('Bid', array('url' => array(
        'controller' => 'bids',
        'action' => 'bidProject',
        $this->Session->read('employee.Id'),
        $pid[0] // project id
    ),
    )
);
echo $this->Form->input('day', array('id' => 'day', 'class' => 'form-control', 'label' => 'Days')) . "</br>";
echo $this->Js->submit(__('Submit', array('before' => $this->Js->get('#sending')->effect('fadeIn'),
        'success' => $this->Js->get('#sending')->effect('fadeOut')
    )), array('class' => 'btn btn-primary')
);
echo $this->Form->end();
}

this is the action bidPorject i have in "BidsController"

 public function bidProject($eid, $pid) {

    $bid = $this->Bid->findByProjectIdAndEmployeeId($pid, $eid);
    if (!$bid) {
        $this->request->data['Bid']['project_id'] = $pid;
        $this->request->data['Bid']['employee_id'] = $eid;

        $this->Bid->create();
        if ($this->Bid->save($this->request->data)) {
            if ($this->request->is('ajax')) {
             //Ajax call
            }
      //$this->Session->setFlash(__('The Bid has been saved'));
        }
    } else {
        $this->Session->setFlash(__('Bid have already done for given Employee Id'));
    }
}

when i click on a submit button neither getting an error nor request is responding and data is unable to store in database. where i am getting problem? how to resolve this issue?

Upvotes: 2

Views: 632

Answers (1)

Aman Dhirendra Verma
Aman Dhirendra Verma

Reputation: 44

Use this code in either layout after all $this-> script (); or after submit button.

$this->Js->writeBuffer(array('inline' => true,'cache' => true))

Upvotes: 1

Related Questions