X-Editable - 如何使用ajax提取表单数据

Hap*_*der 2 javascript ajax jquery twitter-bootstrap x-editable

我正在使用x-editable,并想知道如何使用jquery和ajax填充我的select元素.

[编辑 - 为清晰起见]

这是我的代码:

jQuery(document).ready(function() {

    //toggle `popup` / `inline` mode
    $.fn.editable.defaults.mode = 'popup';

    var getSource = function() {
        var url = "/api/rpc/payments/status_options";
        $.ajax({
            type:  'GET',
            async: true,
            url:   url,
            dataType: "json",

            success: function(responseObject){
            }

        });

    };

    //make status editable
    $('.payments-click').editable({
        type: 'select',
        title: 'Select status',
        placement: 'right',
        value: 2,
        source: getSource()
        /*
         //uncomment these lines to send data on server
         ,pk: 1
         ,url: '/post'
         */
    });

});
Run Code Online (Sandbox Code Playgroud)

我想获得消息来源:

source: getSource()
Run Code Online (Sandbox Code Playgroud)

从函数但不是100%确定如何从Ajax调用返回数据.

Hap*_*der 5

我在这篇文章的帮助下解决了这个问题:如何从异步调用中返回响应?

这是我的解决方案:

jQuery(document).ready(function() {

    //toggle `popup` / `inline` mode
    $.fn.editable.defaults.mode = 'popup';

    function getSource() {
        var url = "/api/rpc/payments/status_options";
        return $.ajax({
            type:  'GET',
            async: true,
            url:   url,
            dataType: "json"
        });
    }

    getSource().done(function(result) {

        $('.payments-click').editable({
            type: 'select',
            title: 'Select status',
            placement: 'right',
            value: 2,
            source: result
            /*
             //uncomment these lines to send data on server
             ,pk: 1
             ,url: '/post'
             */
        });


    }).fail(function() {
        alert("Error with payment status function!")
    });

});
Run Code Online (Sandbox Code Playgroud)