2012-08-02 33 views
0

如何用js helper在cakephp中转换成功?ajax cakephp成功

$.ajax({ 
//(...) 
success:function (data, textStatus) { 
         $("#city-wrap").html(data); 
         $("#AdCityId").selectbox(); 
        }, 
}); 
return false; 

我想这在CakePHP中没有成功:

$this->Js->get('#AdCountryId1')->event('change', 
$this->Js->request(array(
    'controller'=>'cities', 
    'action'=>'getByCountry' 
    ), array(
    'update'=>'#city-wrap', 
    'success'=> '$("#AdCityId").selectbox()';, <= here is what I need ! 
    'async' => true, 
    'method' => 'get', 
    'dataExpression'=>true, 
    'data'=> $this->Js->serializeForm(array(
     'isForm' => true, 
     'inline' => true 
     )) 
    )) 
); 

问候

回答

0

是否实际Ajax调用得到执行?

如果是;试试看看是否真的调用了成功回调。

$this->Js->get('#AdCountryId1')->event('change', 
    $this->Js->request(
     array(
      'controller'=>'cities', 
      'action'=>'getByCountry' 
     ), 
     array(
      'update'=>'#city-wrap', 
      'success'=> "alert('Success!'); $('#AdCityId').selectbox();", 
      'async' => true, 
      'method' => 'get', 
      'dataExpression'=>true, 
      'data'=> $this->Js->serializeForm(array(
       'isForm' => true, 
       'inline' => true 
      )) 
     ) 
    ) 
); 

如果您将看到成功!消息时,有可能出错了$('#AdCityId').selectbox();

0

我同样的问题,我想我找到了一个解决方案看它是否为你工作

$this->Js->get('#AdCountryId1')->event('change', 
$this->Js->request(array(
    'controller'=>'cities', 
    'action'=>'getByCountry' 
    ), array(
    'update'=>'#city-wrap', 
    'success'=> '$("#AdCityId").selectbox()';, <= here is what I need ! 
    'async' => true, 
    'method' => 'get', 
    'dataExpression'=>true, 
    'data'=> $js->serializeForm(array(
     'isForm' => true, 
     'inline' => true 
     )) 
    )) 
); 

试试这个它会工作