Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript X-Editable-如何使用ajax提取表单数据_Javascript_Jquery_Ajax_Twitter Bootstrap_X Editable - Fatal编程技术网

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

Javascript X-Editable-如何使用ajax提取表单数据,javascript,jquery,ajax,twitter-bootstrap,x-editable,Javascript,Jquery,Ajax,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/paym

我正在使用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'
         */
    });

});
我正在尝试获取来源:

source: getSource()

但是我不能100%确定如何从Ajax调用返回数据。

我在这篇文章的帮助下解决了这个问题:

以下是我的解决方案:

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!")
    });

});
试试这个

<a href="javascript:void(0)" id="status" data-type="select" data-title="Select Status"></a>
<script>
    $.getJSON("api/rpc/payments/status_options", function (list) {
            $('#status).editable({
                    prepend: "",
                    pk: 1,
                    source: list,
                    name: "status"
           });
     });
</script>