Search code examples
javascriptdrop-down-menux-editable

X editable - get dropdown option from mysql


I have a list of packages in my database. User need to select what package he wants to use. I want to use the xeditable dropdown bootsrap but the list isn't showing. Always "error when loading list".

I have an example in package.php

function get_package(){
    $data = Array ( 
        array('value' => 1, 'text' => 'package1'),
        array('value' => 2, 'text' => 'package2'),
        array('value' => 3, 'text' => 'package3')
    );

    echo json_encode($data);
}

And below is my js file.

 $('#kitname').editable({
    value:1,
    source: 'package.php'
});

And my html file.

     <a href="#" 
        id="kitname" 
        data-type="select"
        data-name="kitname" 
        data-pk="1" 
        data-value="5" 
        data-original-title="Select Package" 
        "> 
            Select Package 
    </a>

Solution

  • I need this week some time for the same problem, but the solution is very simple. ;) The array contains only: value => text:

    function get_package(){
        $data = Array ( 
            array('1' => 'package1'),
            array('2' => 'package2'),
            array('3' => 'package3')
        );
    
        echo json_encode($data);
    }