practice.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. $(function()
  2. {
  3. $.get(createLink('traincourse', 'ajaxupdatepractice'));
  4. if(!localStorage.getItem('practiceCount'))
  5. {
  6. setTimeout(function() {getData();}, 5000);
  7. }
  8. $('.block-all-practice').on('click', ".update-practice", function()
  9. {
  10. if(confirm(updatePracticeTip))
  11. {
  12. $.get(createLink('traincourse', 'updatepractice'), function(response)
  13. {
  14. if(JSON.parse(response).result === 'success') location.reload();
  15. });
  16. }
  17. });
  18. function getData()
  19. {
  20. $.get(createLink('traincourse', 'ajaxupdatepractice'), function(response)
  21. {
  22. response = JSON.parse(response);
  23. if(response.result === 'success' && response.count > 0 && localStorage.getItem('practiceCount') != response.count)
  24. {
  25. localStorage.setItem('practiceCount', response.count);
  26. $(".practice-data").load(location.href + ' .practice-data');
  27. setTimeout(function() {getData();}, 3000);
  28. }
  29. });
  30. }
  31. });