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,则 html 页面中的元素会更新,但 MySql 行不会更新。

有什么解决方法吗?

非常感谢。

4

1 回答 1

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...
    }
});     
于 2013-04-17T18:47:34.590 回答