2

I am trying to implement Remote Data Select2.

I am accessing data from api. The format is as follows:

concept_id,name
228,Pelecypoda
286,Pelecypoda

When I try to console data in results, it doesn't get consoled. But if I replace the word results with success, I can see the data in console but not in the search results.

Script

$("#search_text").select2({
      minimumInputLength: 3,
      ajax: {
          url: "http://192.241.245.176:4567/api1",
          dataType: 'text',
          type: "GET",
          quietMillis: 250,
          data: function (term) { 
              console.log(term)
              return {
                    q: term.term //search term
              }
           },
           results: function (data,page) {
              console.log(data,"-----RESULTS-----");
              return d3.csv.parse(data, function (d) {
                  console.log(d);
                  return {results: d.name}
               });
            },
            dropdownCssClass: "bigdrop"
});

Can anyone please tell me where am I going wrong? Do I have to specify formatResults and formatSelection provided by select2?

Turnip
  • 35,836
  • 15
  • 89
  • 111
dhara
  • 41
  • 3
  • The problem should be on your url parameter. Is api on a different server than you're running the script? – stefanz Feb 06 '15 at 13:10
  • Yes. The api is on different server. Can you please tell me the way around it? – dhara Feb 06 '15 at 13:21
  • http://stackoverflow.com/questions/1489373/how-to-use-jquery-ajax-for-an-outside-domain – stefanz Feb 06 '15 at 13:27
  • I don't think so the problem is that I am accessing api on different server, because even when I try to save json data in my local system, it doesnt show up the results. – dhara Feb 06 '15 at 13:50
  • What version of Select2 are you using? Because with the new v4.0, the "results" function was renamed to "processResults". – John S Feb 06 '15 at 15:30
  • @JohnS I am using select2 version 3.5.2 – dhara Feb 06 '15 at 16:43

0 Answers0