Garry
Garry

Reputation: 595

how to use Event Options(before,complete) in request method of JsHelper in cakephp 2

I am using cakephp Jshelper for ajax calls.I want to show loader before ajax call but when I add before event option ,ajax call stops working. I am using following code

$data = $this->Js->get('#PostWebadminAdd1Form')->serializeForm(array('isForm' => true, 'inline' => true));
$this->Js->get('#PostWebadminAdd1Form')->event(
        'submit', $this->Js->request(
                array('action' => 'ajax_add_post', 'controller' => 'posts'), array(
            'update' => '#successBox',
            'data' => $data,
            'async' => true,
            'dataExpression' => true,
            'method' => 'POST',
            'before' => $this->Js->get('#loader')->effect('show'),
            //'complete' => $this->Js->get('#loader')->effect('hide'),
                )
        )
);
echo $this->Js->writeBuffer();

Dont know what is the problem here. when i comment line 'before' => $this->Js->get('#loader')->effect('show'), in above code it works fine .

Upvotes: 0

Views: 422

Answers (1)

Ayo Akinyemi
Ayo Akinyemi

Reputation: 777

try:

'before'   => '$("img#loader").attr("style", " ")', 
'complete' => '$("img#loader").attr("style", "display:none")',

Upvotes: 2

Related Questions