如何在cakephp 2中JsHelper的请求方法中使用事件选项(before,complete)
我正在使用cakephp Jshelper进行ajax调用。我想在ajax调用之前显示loader,但当我添加before事件选项时,ajax调用停止工作。我正在使用以下代码如何在cakephp 2中JsHelper的请求方法中使用事件选项(before,complete),php,jquery,ajax,cakephp,cakephp-2.4,Php,Jquery,Ajax,Cakephp,Cakephp 2.4,我正在使用cakephp Jshelper进行ajax调用。我想在ajax调用之前显示loader,但当我添加before事件选项时,ajax调用停止工作。我正在使用以下代码 $data = $this->Js->get('#PostWebadminAdd1Form')->serializeForm(array('isForm' => true, 'inline' => true)); $this->Js->get('#PostWebadminAdd1F
$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();
我不知道这里有什么问题。当我在“=>$this->Js->get(“#loader”)->effect('show')之前注释行时,在上面的代码中效果很好。试试:
'before' => '$("img#loader").attr("style", " ")',
'complete' => '$("img#loader").attr("style", "display:none")',
谢谢#Ayo Akinyemi。这对我来说很有效……但是为什么Jshelper的get和effect方法不起作用呢?