2013-04-16 27 views
0

我一直在試圖找出爲什麼我的某些網頁沒有使用jQuery Mobile的頁面轉換工作時,我發現在我的控制器下面的代碼是打破jQuery Mobile的:CakePHP的JsHelper最新頁面轉換在jQuery Mobile的

public $components = array(
'RequestHandler'); 
public $helpers = array('Js'); 

我在我的控制器中包含了一個ajax函數,我使用JSHelper運行,但是如果可以避免的話,使用Jquery Mobile比JSHelper更重要。我想一些幫助或者a)固定jQuery Mobile的JS帶助手,或b工作)使用jQuery寫下面的功能,避免JSHelper完全:。

<?php 
$this->Js->get('#BagUserId')->event('change', 
    $this->Js->request(array(
     'controller'=>'bags', 
     'action'=>'ajaxload' 
     ), array(
     'update'=>'#user-info', 
     'async' => true, 
     'method' => 'post', 
     'dataExpression'=>true, 
     'data'=> $this->Js->serializeForm(array(
      'isForm' => true, 
      'inline' => true 
      )), 
     )) 
    ); 
?> 

*編輯* *

基於薩姆的答案,我想出了以下內容:

$('#BagUserId').change(function(){ 
     var myData = $('#BagUserId').serialize(); 
     $.ajax({ 
      dataType: 'html', 
      type: "POST", 
      evalScripts: true, 
      async: true, 
      url: myBaseUrl + 'bags/ajaxload', 
      data: myData, 
       success: function (data){ 
        $('#user-info').html(data); 
       }, 
       error: function(){ 
         alert('failure'); 
         }, 
     }); 
    }); 

的URL正常工作,包括這在你的默認視圖的頭,你加載其他腳本之前:

<script type="text/javascript">var myBaseUrl = '<?php echo $this->Html->url('/'); ?>';</script>` 

這樣就可以避免在CakePHP中的JsHelper這(對我來說)是導致在頁面轉換錯誤從我的控制器的所有意見。感謝Sam!

回答

0

你可能需要沿着線的東西:

$('#BagUserId').change(function()){ 
    $.post('bags/ajaxload', $('#my_form_id').serializeArray()); 
};