jQuery Select2 not displaying Data

≯℡__Kan透↙ 提交于 2021-02-11 15:26:40

问题


I am stuck at problem where i believe i am getting the response in correct format but i am not able to display the data returned from the server. Intelligent Minds! I need your help.

Below is my HTML code:

    <div class="form-group">
      <select id="owner" class="dropDowns">
        <option value="00000" selected="selected">Select Owner</option>
    </select>
    </div>

JQuery Code:

This function is getting called with no problems and a result is also returned from the server but some how i am not able to format that result and display it to the user. I am not sure what i am doing wrong and this has been bugging me for quiet some time now.

$("#owner").select2({
     minimumInputLength: 3,
      ajax: {
        url: "http://localhost:8080/iam/aexp/rest/ePAAS/getOwner",
        dataType: "jsonp",
                headers: {
                    "Authorization": "Basic " + btoa('spadmin' + ":" + 'admin')
        },
        type: 'GET',
        delay: 250,
        data: function (params) {
          return {
            adsId: params.term, // search term

          };
        },
        processResults: function (data) {

          return {
            results: data
          };
        },
        cache: true
      },
      formatResult: function (data) {
                  return "<div>" + data.id + "</div>";
              },
        formatSelection: function (data) {
             return data.id;
        }


    });

And here is the response I am getting from the server:

[{"id":0,"text":"rgadke"}]

Thanks!


回答1:


I found the issue. I was not returning the result in the correct JSON format



来源:https://stackoverflow.com/questions/31800529/jquery-select2-not-displaying-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!