Can not create option via ajax


#1

Hi!
I can not create option via ajax. The data format is same as document requirement.

$('#name').select2({
        ajax: {            
            url: '/order/create/name',
            dataType: 'json',  
            delay: 250,
            processResults: function (data) {
                console.log(data);
                return  data;
            },
            cache: true
        },
    });

response data as below:
%E5%9B%BE%E7%89%87

However it do not work!


#2

The reasult as below:

Not any search result


#3

The console.log result:


#4

Is there something I missed?


#5

Only static data works, I don’t konw why:

<script>
    $('#name').select2({
        ajax: {             
            url: '/order/create/name',
            dataType: 'json',  
            delay: 250,
            processResults: function (data) {
                
                return {
                    results: [{"id":3,"text":"hello world!"}]
                };
            },
            cache: true
        },
    });    
</script>


#6

Oh! yes!
I solved this problem.
%E5%9B%BE%E7%89%87

The elements in array are not json!


#7

How to close this issue?

Sir?


#8

I’m glad you solved your problem. There isn’t a way to “close” an issue, since this is just a discussion forum. If you can edit the title of this thread, you could put “[SOLVED]” in front of the current title. That way people reading the forum will know that the issue is solved.