$(function () { var url = '../api/Tasks/'; var htmlTask = '
  • {0}{1}{2}'; htmlTask += '
  • '; function listData(options) { options = $.extend({ url: url, animation: true, ctl: $('a.fa-refresh') }, options); if (options.animation) options.ctl.toggleClass('fa-spin'); $.ajax({ url: options.url, type: 'GET', success: function (result) { if (result) { var content = result.Users.map(function (task) { var t = new Date(task.AssignTime).format('yyyy-MM-dd HH:mm:ss'); return $.format(htmlTask, task.TaskName, task.UserName, t, task.ID); }).join(''); $('#list-task').html(content); } if (options.animation) options.ctl.toggleClass('fa-spin'); }, error: function (XMLHttpRequest, textStatus, errorThrown) { if (options.animation) options.ctl.toggleClass('fa-spin'); } }); } listData(); $('a.fa-refresh').on('click', function () { listData({ ctl: $(this) }); }); })