Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $('.container').on('click', 'button.next', function(e){
- e.preventDefault();
- let rel = $(this).attr('rel');
- let forms = $('form.question');
- if (forms[0].checkValidity() === false){
- event.stopPropagation();
- }else{
- $(this).attr('disabled');
- let page = 'quest/' + rel + '.php';
- let mas = forms.serializeArray();
- let app = JSON.parse(localStorage.getItem('app'));
- if (rel<6) {
- if (app===null){
- app = mas;
- localStorage.clear();
- localStorage.setItem('app', JSON.stringify(app));
- }else{
- $.each(mas, function (index, value) {
- if (app.value.name===undefined){
- alert(app.value.name);
- app.push(value);
- }else{
- delete app[value.name];
- app[value.name]=value.value;
- }
- //app.push(value);
- });
- localStorage.clear();
- localStorage.setItem('app', JSON.stringify(app));
- }
- console.clear();
- console.log(app);
- $.get(page).done(function (response) {
- $("div.quest").fadeOut(100, function () {
- $('div.quest').html(response).fadeIn(800);
- })
- }).fail(function () {
- $("div.quest").prepend('Ошибка');
- });
- }else{
- if ($('.container input[type="checkbox"]').is(':checked')){
- $.each(mas, function (index, value) {
- $.each(value, function (i, v) {
- //app.push(value);
- app[i]=v;
- });
- });
- console.clear();
- console.log(app);
- $.ajax({
- url: "quest/action.php",
- dataType: "HTML",
- type: "POST",
- data: app,
- success: function(res){
- $("div.quest").fadeOut(100, function () {
- $('div.quest').html(res).fadeIn(800);
- localStorage.clear();
- })
- },
- error: function(){
- console.log('Ошибка AJAX запроса');
- }
- });
- }else
- alert('Дайте свое согласие на передачу данных');
- }
- }
- forms.addClass('was-validated');
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement