Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $('.container').on('click', 'button.next', function(e){
  2.    e.preventDefault();
  3.    let rel = $(this).attr('rel');
  4.    let forms = $('form.question');
  5.    if (forms[0].checkValidity() === false){
  6.        event.stopPropagation();
  7.    }else{
  8.        $(this).attr('disabled');
  9.        let page = 'quest/' + rel + '.php';
  10.        let mas = forms.serializeArray();
  11.        let app = JSON.parse(localStorage.getItem('app'));
  12.        if (rel<6) {
  13.            if (app===null){
  14.                app = mas;
  15.                localStorage.clear();
  16.                localStorage.setItem('app', JSON.stringify(app));
  17.            }else{
  18.                $.each(mas, function (index, value) {
  19.                    if (app.value.name===undefined){
  20.                        alert(app.value.name);
  21.                        app.push(value);
  22.                    }else{
  23.                        delete app[value.name];
  24.                        app[value.name]=value.value;
  25.                    }
  26.                    //app.push(value);
  27.                });
  28.                localStorage.clear();
  29.                localStorage.setItem('app', JSON.stringify(app));
  30.            }
  31.            console.clear();
  32.            console.log(app);
  33.            $.get(page).done(function (response) {
  34.                $("div.quest").fadeOut(100, function () {
  35.                    $('div.quest').html(response).fadeIn(800);
  36.                })
  37.            }).fail(function () {
  38.                $("div.quest").prepend('Ошибка');
  39.            });
  40.        }else{
  41.            if ($('.container input[type="checkbox"]').is(':checked')){
  42.                $.each(mas, function (index, value) {
  43.                    $.each(value, function (i, v) {
  44.                        //app.push(value);
  45.                        app[i]=v;
  46.                    });
  47.                });
  48.                console.clear();
  49.                console.log(app);
  50.                $.ajax({
  51.                    url: "quest/action.php",
  52.                    dataType: "HTML",
  53.                    type: "POST",
  54.                    data: app,
  55.  
  56.                    success: function(res){
  57.                        $("div.quest").fadeOut(100, function () {
  58.                            $('div.quest').html(res).fadeIn(800);
  59.                            localStorage.clear();
  60.                        })
  61.                    },
  62.                    error: function(){
  63.                        console.log('Ошибка AJAX запроса');
  64.                    }
  65.                });
  66.            }else
  67.                alert('Дайте свое согласие на передачу данных');
  68.        }
  69.    }
  70.    forms.addClass('was-validated');
  71. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement