Guest User

Untitled

a guest
Jan 23rd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. var jQ = false;
  2. function initJQ() {
  3. if (typeof(jQuery) == 'undefined') {
  4. if (!jQ) {
  5. jQ = true;
  6. document.write('<scr' + 'ipt type="text/javascript" > > >src="http://code.jquery.com/jquery-1.7.0.js"></scr' + 'ipt>');
  7. }
  8. setTimeout('initJQ()', 50);
  9. }
  10. else {
  11. (function($) {
  12. $(function() {
  13. $("#reg-form").on('submit',function(){
  14. var arr = $('#reg-form').serializeArray();
  15. var ok=true;
  16. $.ajax({
  17. url:'index.php?option=com_admin&task=ajaxValidate',
  18. type:'post',
  19. async:false,
  20. data:{'reg_data':arr},
  21. success:function(resp)
  22. {
  23. if(resp=='done')
  24. {
  25. return true;
  26. }
  27. else
  28. {
  29. $('#alert').show();
  30. ok=false;
  31. }
  32. }
  33. });
  34. if(!ok)
  35. return false;
  36. })
  37. })
  38. })(jQuery)
  39. }
  40. }
  41. initJQ();
  42.  
  43. var script=document.createElement('script');
  44. script.src='http://code.jquery.com/jquery-1.7.0.js';
  45. document.head.appendChild(script);
  46. script.onload=initJQ;
  47.  
  48. if (!jQ) {
  49. jQ = true;
  50. document.write('<scr' + 'ipt type="text/javascript" src="http://code.jquery.com/jquery-1.7.0.js"></scr' + 'ipt>');
  51. }
  52. setTimeout('initJQ()', 50);
  53.  
  54. function initJQ() {
  55. if (typeof (jQuery) == 'undefined') {
  56. var script = document.createElement('script');
  57. script.src = 'http://code.jquery.com/jquery-1.7.0.js';
  58. document.head.appendChild(script);
  59. script.onload = runJQ; //другая функция, чтобы незациклиться
  60.  
  61. } else runJQ();
  62.  
  63. function false_ret() {
  64. return false;
  65. }
  66.  
  67. function runJQ() {
  68. jQuery(function ($) {
  69. var $reg_form = $("#reg-form");
  70.  
  71. function error_trigger() {
  72. $reg_form.unbind('submit.myns'); //убираем return false
  73. $reg_form.one('submit', checkform); //возвращаем хэндлер проверки
  74. $('#alert').show();
  75. }
  76.  
  77. function checkform() {
  78. $reg_form.bind('submit.myns',false_ret); //не даем сабмитить еще раз,
  79. // до окончания запроса,
  80. // используем namespace myns,
  81. // чтобы не перекрыть другие хэндлеры submit
  82. var arr = $reg_form.serializeArray();
  83. $.ajax({
  84. url: 'index.php?option=com_admin&task=ajaxValidate',
  85. type: 'post',
  86. async: true, //делаем асинхронно, синхронно - плохо
  87. data: {
  88. 'reg_data': arr
  89. },
  90. success: function (resp) {
  91. if (resp == 'done') {
  92. $reg_form.unbind('submit.myns'); //убираем return false
  93. $reg_form.submit(); //всё хорошо. отправляем форму
  94. return true;
  95. } else {
  96. error_trigger();
  97. }
  98. },
  99. error: error_trigger
  100. });
  101. return false; //не сабмитим до проверки
  102. }
  103. $reg_form.one('submit', checkform); //один раз
  104. });
  105. }
  106. }
  107. initJQ();
  108.  
  109. setTimeout(initJQ, 50);
  110.  
  111. (function($) {
  112. $(function() {
  113. /* code here */
  114. })
  115. })(jQuery)
Add Comment
Please, Sign In to add comment