2013-04-15 61 views
0
$(function(){ 



      //enable/disable 
      $('#enable').click(function() { 
       $('#user .editable').editable('http://domain.com/update.php'); 
      });  

      //modify buttons style 
      $.fn.editableform.buttons = 
      '<button type="submit" class="btn btn-success editable-submit btn-mini"><i class="icon-ok icon-white"></i></button>' + 
      '<button type="button" class="btn editable-cancel btn-mini"><i class="icon-remove"></i></button>'; 

      //editables 
      $('.remarks').editable({ 
       url: 'http://domain.com/update.php', 
       display: function(value, response) { 
       //render response into element 
       $(this).html(response); 
       } 
      }); 



      //ajax emulation. 
      $.mockjax({ 
       url: 'http://domain.com/update.php', 
       responseTime: 400, 
       response: function(settings) { 
       this.responseText = settings.data.value; 
       } 
      }); 


     }); 

不使用Mockjax,MySQL的行更新的工作,但在HTML頁面中的元素不會被更新。Mockjax擾亂X編輯更新(AJAX)

如果我使用Mockjax,html頁面中的元素已更新,但MySql行未更新。

有沒有解決這個問題的方法?

非常感謝。

回答

0

你爲什麼使用mockjax?根據我的理解,mockjax只是用於模擬目的,您應該使用ajax。像這樣:

$('#a').editable({ 
    validate: function(value) { 
     if($.trim(value) == '') return 'This value is required.'; 
    }, 
    type: 'text', 
    url: '/post', 
    pk: '123', // id of the row in your db... 
    title: 'Enter Value', 
    params: function(params) { 
     var data = {}; 
     data['id'] = line; 
     data['field'] = params.name; 
     data['value'] = params.value; 
     return data; 
    }, 
    ajaxOptions: { 
     dataType: 'json' 
    }, 
    display: function(value, response) { 
     $(this).text(response.new_value_from_server); 
    }, 
    success: function(response, newValue) { 
     // output what ever you want here if the submit was successfull... 
    } 
});