Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. $('#query').keypress(function (e) {
  2. if(e.which == 13) {
  3. var input = $('input:text').val();
  4. var inpString = input.split(' ');
  5. var finalQuery = "";
  6. for(var words=0; words<inpString.length; words++) {
  7. finalQuery += inpString[words] + '+';
  8. }
  9.  
  10. finalQuery = finalQuery.substring(0, finalQuery.length-1);
  11. loadArticles(finalQuery);
  12. console.log('wtf');
  13. }
  14. });
  15.  
  16. function loadArticles(keywords) {
  17. $.ajax({
  18. url: 'https://en.wikipedia.org/w/api.php?action=query&format=json&list=search&utf8=1&srsearch=' + keywords,
  19. success: function(data) {
  20. console.log(data.query.searchinfo.totalhits);
  21. },
  22. failure: function(data) {
  23. console.log(data);
  24. },
  25. datatype: 'json'
  26. });
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement