Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1.  
  2. this.options = {
  3. 'app_url': $(document).find('[name="APP_URL"]').attr('content'),
  4. 'api': $(document).find('[name="APP_URL"]').attr('content') + '/api/plano-contas',
  5. 'token': $(document).find('[name="_token"]').attr('content')
  6. };
  7.  
  8.  
  9. /**
  10. *
  11. */
  12. this.callSS = function (data, callback) {
  13.  
  14. var call = {
  15. url: this.options.api,
  16. data: data,
  17. dataType: "json",
  18. type: "GET",
  19. success: function (data) {
  20.  
  21. if(typeof callback === 'function') {
  22.  
  23. callback(data);
  24.  
  25. } else {
  26.  
  27. console.log('----------> success');
  28. console.log(data);
  29. console.log('');
  30.  
  31. }
  32.  
  33. },
  34. error: function (xhr, ajaxOptions, thrownError) {
  35.  
  36. console.error('----------> error');
  37. console.error(xhr);
  38. console.error(ajaxOptions);
  39. console.error(thrownError);
  40. console.log('');
  41.  
  42. }
  43. };
  44.  
  45. if(typeof callback == 'object') {
  46.  
  47. call = $.extend({}, call, callback);
  48.  
  49. }
  50.  
  51. call.data._token = this.options.token;
  52.  
  53. $.ajax(call);
  54.  
  55. };
  56.  
  57.  
  58. /**
  59. *
  60. */
  61. this.url = function(str) {
  62.  
  63. this.options.app_url + str;
  64.  
  65. };
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78. // data e success
  79. this.callSS({}, function() {
  80. alert("hue");
  81. });
  82.  
  83.  
  84.  
  85. // data forma completa
  86. this.callSS({}, {
  87. 'success': function() {
  88. },
  89. 'error': function() {
  90. }
  91. });
  92.  
  93.  
  94. // data forma completa
  95. this.callSS({}, {
  96. 'url': this.url('/asdfasdfasdfasdfasdfasdf'),
  97. 'success': function() {
  98. },
  99. 'error': function() {
  100. }
  101. });
  102.  
  103.  
  104.  
  105. // data forma completa
  106. this.callSS({}, {
  107. 'url': 'http://www.google.com',
  108. 'success': function() {
  109. },
  110. 'error': function() {
  111. }
  112. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement