admin管理员组

文章数量:1318563

I create plugin to create wizards using jquery steps. I save all step's values into variable and using ajax to process it, then show using wp ajax function

but only one variable in ajax inserted into wp ajax function, other one value empty but when I see inside console log after ajax success. it have have value.

only variable answer have value but results_wizard don't have value.

    var answer = [], results_wizards = [],
    stepsWizard = jQuery("#wizard").steps({
        headerTag: "h2",
        bodyTag: "section",
        transitionEffect: "slideLeft",
        enablePagination: false,
        titleTemplate: "#title#",

        onStepChanged: function (event, currentIndex, priorIndex) { 
            $('html, body').animate({
                scrollTop: $("#row-wizard-letselschade").offset().top - 80
            });
            $('input[name="wiz-'+priorIndex+'"]:checked').each(function(i){
                if(jQuery.inArray($(this).val(),answer) == -1){
                    // the element is not in the array
                    answer.push($(this).val());
                    results_wizards[$(this).val()] = $("label[for='"+this.id+"']").text();
                    
                };
                
            
                
            });
            $("input:checkbox:not(:checked)").each(function(i){
                var removeItem = $(this).val();
                answer = jQuery.grep(answer, function(value) {
                      return value != removeItem;
                    });
                });
            
            },
        onFinished: function (event, currentIndex)
        {
            $('input[name="wiz-'+currentIndex+'"]:checked').each(function(i){
                if(jQuery.inArray($(this).val(),answer) == -1){
                    // the element is not in the array
                    answer.push( $(this).val());
                }; 
                
            });
            
            var dataAnswerNew = {
                    'action': 'wizard_answers',
                    'answer':answer, 
                    'results_wizards': results_wizards,
                };
            $.post(whwz_ajaxurl, dataAnswerNew, function(response){
                console.log(results_wizards);
                $('.wizard-answer').html(response);
                
                var form_id = $('.wpcf7').attr('id');
                $('.wpcf7 > form').attr('action', '/#' + form_id);
                wpcf7.initForm( jQuery('.wpcf7-form') );
                
                

                });
        }
    });

here my ajax

  var dataAnswerNew = {
                'action': 'wizard_answers',
                'answer':answer, 
                'results_wizards': results_wizards,
            };
        $.post(whwz_ajaxurl, dataAnswerNew, function(response){
            console.log(results_wizards);
            $('.wizard-answer').html(response);

            var form_id = $('.wpcf7').attr('id');
            $('.wpcf7 > form').attr('action', '/#' + form_id);
            wpcf7.initForm( jQuery('.wpcf7-form') );



            });

本文标签: pluginsCannot pass value variable to WP AJAX functions