Search code examples
ajaxresponseselectize.js

What does selectize expect as a return in order to load a select


I have a normal ajax call that is working correctly. I have tried passing data back multiple ways. What is selectize expecting in order to populate the select?

kick_subset.load(function(callback) {

                xhr && xhr.abort();
                    xhr = $.ajax({
                    url: 'ajax/selectize.php',
                    dataType: 'json',
                    data:({client: value}),
                    success: function(results) {
                        kick_subset.enable();
                        callback(results);
                    },
                    error: function() {
                        callback();
                    }
                    })
                    });

Solution

  • So it took me a while but i finally figured it out. It looks for the following format:

    [{"id":0,"value":"one"},{"id":1,"value":"two"}]

    I did the following to test/make it work:

    $one = array("id" => 0, "value" => "one");
    $two = array("id" => 1, "value" => "two");
    
    $subsets = array($one,$two);
    echo json_encode($subsets);