Advertisement
Guest User

Untitled

a guest
May 28th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. /* jsonp.js, (c) Przemek Sobstel 2012, License: MIT */
  2.  
  3. var $jsonp = (function(){
  4. var that = {};
  5.  
  6. that.send = function(src, options) {
  7. var options = options || {},
  8. callback_name = options.callbackName || 'callback',
  9. on_success = options.onSuccess || function(){},
  10. on_timeout = options.onTimeout || function(){},
  11. timeout = options.timeout || 10;
  12.  
  13. var timeout_trigger = window.setTimeout(function(){
  14. window[callback_name] = function(){};
  15. on_timeout();
  16. }, timeout * 1000);
  17.  
  18. window[callback_name] = function(data){
  19. window.clearTimeout(timeout_trigger);
  20. on_success(data);
  21. };
  22.  
  23. var script = document.createElement('script');
  24. script.type = 'text/javascript';
  25. script.async = true;
  26. script.src = src;
  27.  
  28. document.getElementsByTagName('head')[0].appendChild(script);
  29. };
  30.  
  31. return that;
  32. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement