Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var jQ = false;
- function initJQ() {
- if (typeof(jQuery) == 'undefined') {
- if (!jQ) {
- jQ = true;
- document.write('<scr' + 'ipt type="text/javascript" > > >src="http://code.jquery.com/jquery-1.7.0.js"></scr' + 'ipt>');
- }
- setTimeout('initJQ()', 50);
- }
- else {
- (function($) {
- $(function() {
- $("#reg-form").on('submit',function(){
- var arr = $('#reg-form').serializeArray();
- var ok=true;
- $.ajax({
- url:'index.php?option=com_admin&task=ajaxValidate',
- type:'post',
- async:false,
- data:{'reg_data':arr},
- success:function(resp)
- {
- if(resp=='done')
- {
- return true;
- }
- else
- {
- $('#alert').show();
- ok=false;
- }
- }
- });
- if(!ok)
- return false;
- })
- })
- })(jQuery)
- }
- }
- initJQ();
- var script=document.createElement('script');
- script.src='http://code.jquery.com/jquery-1.7.0.js';
- document.head.appendChild(script);
- script.onload=initJQ;
- if (!jQ) {
- jQ = true;
- document.write('<scr' + 'ipt type="text/javascript" src="http://code.jquery.com/jquery-1.7.0.js"></scr' + 'ipt>');
- }
- setTimeout('initJQ()', 50);
- function initJQ() {
- if (typeof (jQuery) == 'undefined') {
- var script = document.createElement('script');
- script.src = 'http://code.jquery.com/jquery-1.7.0.js';
- document.head.appendChild(script);
- script.onload = runJQ; //другая функция, чтобы незациклиться
- } else runJQ();
- function false_ret() {
- return false;
- }
- function runJQ() {
- jQuery(function ($) {
- var $reg_form = $("#reg-form");
- function error_trigger() {
- $reg_form.unbind('submit.myns'); //убираем return false
- $reg_form.one('submit', checkform); //возвращаем хэндлер проверки
- $('#alert').show();
- }
- function checkform() {
- $reg_form.bind('submit.myns',false_ret); //не даем сабмитить еще раз,
- // до окончания запроса,
- // используем namespace myns,
- // чтобы не перекрыть другие хэндлеры submit
- var arr = $reg_form.serializeArray();
- $.ajax({
- url: 'index.php?option=com_admin&task=ajaxValidate',
- type: 'post',
- async: true, //делаем асинхронно, синхронно - плохо
- data: {
- 'reg_data': arr
- },
- success: function (resp) {
- if (resp == 'done') {
- $reg_form.unbind('submit.myns'); //убираем return false
- $reg_form.submit(); //всё хорошо. отправляем форму
- return true;
- } else {
- error_trigger();
- }
- },
- error: error_trigger
- });
- return false; //не сабмитим до проверки
- }
- $reg_form.one('submit', checkform); //один раз
- });
- }
- }
- initJQ();
- setTimeout(initJQ, 50);
- (function($) {
- $(function() {
- /* code here */
- })
- })(jQuery)
Add Comment
Please, Sign In to add comment