loading remote data

Select2 comes with AJAX/JSONP support built in. in this example we will search for a movie using Rotten Tomatoes API:

eg code:

  1. $(“#e6”).select2({
  2. placeholder: {title: “Search for a movie”, id: “”},
  3. minimumInputLength: 1,
  4. ajax: { // instead of writing the function to execute the request we use Select2’s convenient helper
  5. url: “http://api.rottentomatoes.com/api/public/v1.0/movies.json”,
  6. dataType: ‘jsonp’,
  7. data: function (term, page) {
  8. return {
  9. q: term, // search term
  10. page_limit: 10,
  11. apikey: “ju6z9mjyajq2djue3gbvv26t” // please do not use so this example keeps working
  12. };
  13. },
  14. results: function (data, page) { // parse the results into the format expected by Select2.
  15. // since we are using custom formatting functions we do not need to alter remote JSON data
  16. return {results: data.movies};
  17. }
  18. },
  19. formatResult: movieFormatResult, // omitted for brevity, see the source of this page
  20. formatSelection: movieFormatSelection // omitted for brevity, see the source of this page
  21. });

Select2 uses jQuery’s $.ajax function to execute the remote call by default. an alternative transport function can be specified in the ajax settings@ an entirely custom implementation can be built by providing a custom query function instead of using the ajax helper.

42 responses »

  1. l-theanine says:

    I appreciate your rich words. good contribution. I hope you release many. I will carry on watching

  2. You have mentioned very interesting points! ps nice website.

  3. Diego Speltz says:

    Very interesting information!Perfect just what I was searching for!

  4. This writing has inspired me to continue focusing on my own blog

  5. nootropic says:

    Hello, i think that i noticed you visited my weblog thus i came to “return the favor”.I’m trying to to find things to enhance my website!I assume its ok to use a few of your ideas!!

  6. nootropic says:

    Greeting from across the sea. informative post I will return for more.

  7. jailbreak says:

    Hi, i believe that i noticed you visited my website thus i got here to “go back the favor”.I’m trying to to find issues to enhance my web site!I assume its good enough to make use of a few of your ideas!!

  8. jailbreak says:

    I love your intriguing writing. excellent contribution. I hope you produce many. I will carry on reading

  9. Very great information can be found on this website.

  10. theaninel says:

    I like your useful blog. super contribution. I hope you produce more. I will carry on reading

  11. Rattling great info can be found on this web blog.

  12. d3 items says:

    Hello, i think that i saw you visited my blog thus i got here to “return the choose”.I’m attempting to to find things to enhance my website!I suppose its adequate to use some of your ideas!!

  13. d3 items says:

    You have remarked very interesting points! ps nice website.

  14. d3 gold says:

    Very interesting info!Perfect just what I was looking for!

  15. d3 gold says:

    This writing has inspired me to continue working on my own blog

  16. Edelmira says:

    it’s glad to read this post! i like it. http://www.maladiretasegmentada.com.br

  17. jailbreak says:

    Hey, I just stopped in to visit your website and thought I’d say I had a great visit.

  18. jailbreak says:

    Hi, i believe that i noticed you visited my web site so i got here to “go back the want”.I am attempting to find issues to enhance my website!I suppose its adequate to make use of some of your ideas!!

  19. vitamins says:

    Hello, i feel that i saw you visited my site so i got here to “go back the favor”.I’m attempting to in finding issues to enhance my site!I guess its good enough to make use of a few of your ideas!!

  20. vitamin says:

    Greeting from across the world. informative post I must return for more.

  21. We love our Kindle Fire, but as many people have said it has some drawbacks when compared to the iPad, especially on size and power. But I’m impressed with the new specs of the Kindle Fire 2 with the 10inch screen. Some of the new specs are at kindlemad.com and I think they will be opening up pre-orders soon.

  22. Great stuff excellent information

  23. picamilon says:

    Very interesting information!Perfect just what I was looking for!

  24. nootropics says:

    Hi, i think that i noticed you visited my website thus i got here to “return the favor”.I’m attempting to to find issues to enhance my site!I suppose its ok to use a few of your ideas!!

  25. picamilon says:

    Hello, I just stopped by to visit your blog and thought I’d say I had a great visit.

  26. notropics says:

    Hi, I just stopped by to visit your blog and thought I’d say I had a great visit.

  27. This blog has inspired me to carry on focusing on my own blog

  28. nootropics says:

    Cheers, I just stopped in to visit your website and thought I’d say thank you.

  29. nootropic says:

    Cheers, I just stopped by to visit your blog and thought I’d say I had a great visit.

  30. Very interesting info!Perfect just what I was searching for!

  31. We would definitely thanks a ton again. I don’t know informed me may well worn out the lack of full proposals brought as a result of your self an extraordinarily principle. It actually was probably the most not easy challenge an enormous, but when you consider a complete competent manner you have regulated who taught me to be to be able to advance sufficient reason for impress. Along with certainly much more for those who are assist you to and therefore genuinely we imagine you perspiring a terrific process you will be starting guidance other types of those who the use of a web pages. Will you have never heard of everyone.

  32. aion kinah says:

    I pondered posting this pingback wonderful gadget

  33. yecats131 says:

    This was taken directly from the creators website on Github. It would be useful to see a different example.

  34. Congrats on your award! That is fantastic …

  35. Bas Jansen says:

    You really make it seem really easy along with your presentation but I find this matter to be really something which I think I’d never understand. It sort of feels too complicated and very extensive for me. I’m taking a look forward for your subsequent put up, I will try to get the grasp of it!

  36. Real nice layout and fantastic subject material , very little else we require : D.

  37. a3319214 says:

    I’ve said that least 3319214 times. SCK was here

  38. tb3319214@3319214…

    I’ve said that least 3319214 times….

As salam. Hi. Leave a Comment?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s