Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery回调启动jQuery结束_Javascript_Jquery - Fatal编程技术网

Javascript jQuery回调启动jQuery结束

Javascript jQuery回调启动jQuery结束,javascript,jquery,Javascript,Jquery,如果有人能帮我修复这个脚本,我将不胜感激 我会提供一个提琴,但提琴的行为与wordpress iframe中的不同,但我相信我已经解决了大部分代码(如果有更好的方法编写此代码,请更正我) 我相信我需要在出现错误后重新启动jQuery脚本,现在我可以让脚本在用户单击带有无效条目的按钮后显示电子邮件输入框,但由于我正在使用的库,我必须从头开始启动脚本,我不确定如何正确执行 我尝试使用初始函数作为回调函数,但不断出现错误,因为我再次需要api信息和所有测量参数 下面是我认为问题所在的代码部分,是否可以

如果有人能帮我修复这个脚本,我将不胜感激

我会提供一个提琴,但提琴的行为与wordpress iframe中的不同,但我相信我已经解决了大部分代码(如果有更好的方法编写此代码,请更正我)

我相信我需要在出现错误后重新启动jQuery脚本,现在我可以让脚本在用户单击带有无效条目的按钮后显示电子邮件输入框,但由于我正在使用的库,我必须从头开始启动脚本,我不确定如何正确执行

我尝试使用初始函数作为回调函数,但不断出现错误,因为我再次需要api信息和所有测量参数

下面是我认为问题所在的代码部分,是否可以添加回调以在出现错误时重新启动脚本

/**我需要帮助的部分代码**/

 if(data.submitSurveyResponse.success == 'false') {
            $('input[type=text]').hide();
            $('#ACTION_SUBMIT_SURVEY_RESPONSE').hide();
            $('#cons_email').show().select();
            $('#NextStepForm').show();
          $('.survey-form').prepend('<div id="survey-errors">' + 
                                      '<div class="alert alert-danger">' + 
                                        'There was an error with your submission. Please try again.' + 
                                      '</div>' + 
                                    '</div>');
if(data.submitSurveyResponse.success=='false'){
$('input[type=text]')。隐藏();
$(“#操作#提交(调查)响应”).hide();
$('cons#u email').show().select();
$('#NextStepForm').show();
$('.survey form')。前缀('+
'' + 
“您的提交有错误。请重试。”+
'' + 
'');
/**代码段结束**/

/**开始jQuery脚本**/

 (function($) {
  /* init variables */
  luminateExtend({
    apiKey: 'Key', 
    path: {
      nonsecure: 'http://mywebsite.com', 
      secure: 'https://mywebsite.com'
    }

  });

 $(function() {
$('#NextStepForm').click( function(e) {
     if ($('input[type=email]').val().length > 0) {
         e.preventDefault();
        $('input[type=email]').fadeOut(1000);
    $('#NextStepForm').hide();
    $('input[type=text]').fadeIn(1000).removeClass('hidden');
    $('#ACTION_SUBMIT_SURVEY_RESPONSE').removeClass('hidden');

    }
});

    /* UI handlers for the Survey example */
    if($('.survey-form').length > 0) {
      $('.survey-form').submit(function() {
        window.scrollTo(0, 0);
        $(this).hide();
        $(this).before('<div class="well survey-loading">' + 
                         'Processing...' + 
                       '</div>');
      });
    }

    /* handle the Survey form submission */
    /* if the Survey is submitted succesfully, display a thank you message */
    /* if there is an error, display it inline */
    window.submitSurveyCallback = {
      error: function(data) {
        $('#survey-errors').remove();
        $('.survey-form .form-group .alert').remove();

        $('.survey-form').prepend('<div id="survey-errors">' + 
                                      '<div class="alert alert-danger">' + 
                                        data.errorResponse.message + 
                                      '</div>' + 
                                    '</div>');

        $('.survey-loading').remove();
        $('.survey-form').show();
      }, 
      success: function(data) {
        $('#survey-errors').remove();
        $('.survey-form .form-group .survey-alert-wrap').remove();

        if(data.submitSurveyResponse.success == 'false') {
            $('input[type=text]').hide();
            $('#ACTION_SUBMIT_SURVEY_RESPONSE').hide();
            $('#cons_email').show().select();
            $('#NextStepForm').show();
          $('.survey-form').prepend('<div id="survey-errors">' + 
                                      '<div class="alert alert-danger">' + 
                                        'There was an error with your submission. Please try again.' + 
                                      '</div>' + 
                                    '</div>');

          var surveyErrors = luminateExtend.utils.ensureArray(data.submitSurveyResponse.errors);
          $.each(surveyErrors, function() {
            if(this.errorField) {
              $('input[email="' + this.errorField + '"]').closest('.form-group')
                                                        .prepend('<div class="col-sm-12 survey-alert-wrap">' + 
                                                                    '<div class="alert alert-danger">' +
                                                                     this.errorMessage + 
                                                                   '</div>' + 
                                                                 '</div>');
            }
          });

          $('.survey-loading').remove();
          $('.survey-form').show();
        }
        else {
          $('.survey-loading').remove();
          $('.survey-form').before('<div class="alert alert-success">' + 
                                 '<p>Thanks for joining. You should receive your first issue of the e-newsletter shortly.</p>' + 
                                     '</div>');
        }
      }
    };
    /* bind any forms with the "luminateApi" class */
    luminateExtend.api.bind();
  });
})(jQuery);
(函数($){
/*初始变量*/
发光体({
apiKey:'Key',
路径:{
不安全:'http://mywebsite.com', 
安全:'https://mywebsite.com'
}
});
$(函数(){
$(“#下一步表单”)。单击(函数(e){
if($('input[type=email]').val().length>0){
e、 预防默认值();
$('input[type=email]')。淡出(1000);
$('#NextStepForm').hide();
$('input[type=text]').fadeIn(1000).removeClass('hidden');
$(“#操作"提交"调查"响应”).removeClass('hidden');
}
});
/*调查示例的UI处理程序*/
如果($('.survey form')。长度>0){
$('.survey form')。提交(函数(){
滚动到(0,0);
$(this.hide();
$(本)。在(“”+
“正在处理…”
'');
});
}
/*处理调查表格的提交*/
/*如果调查成功提交,则显示感谢消息*/
/*如果有错误,请以内联方式显示*/
window.submitSurveyCallback={
错误:函数(数据){
$(“#调查错误”).remove();
$('.survey form.form group.alert').remove();
$('.survey form')。前缀('+
'' + 
data.errorResponse.message+
'' + 
'');
$('.survey loading').remove();
$('.survey form').show();
}, 
成功:功能(数据){
$(“#调查错误”).remove();
$('.survey form.form group.survey alert wrap').remove();
如果(data.submitSurveyResponse.success=='false'){
$('input[type=text]')。隐藏();
$(“#操作#提交(调查)响应”).hide();
$('cons#u email').show().select();
$('#NextStepForm').show();
$('.survey form')。前缀('+
'' + 
“您的提交有错误。请重试。”+
'' + 
'');
var surveyErrors=luminateExtend.utils.ensureArray(data.submitSurveyResponse.errors);
$.each(调查者,函数(){
if(此.errorField){
$('input[email=“”+this.errorField+''“]')。最近('.form group'))
.prepend(“”+
'' +
此.errorMessage+
'' + 
'');
}
});
$('.survey loading').remove();
$('.survey form').show();
}
否则{
$('.survey loading').remove();
$('.survey form')。在('+
“感谢您的加入。您很快就会收到第一期电子通讯。

”+ ''); } } }; /*使用“luminateApi”类绑定任何表单*/ luminateExtend.api.bind(); }); })(jQuery);
/**结束jQuery脚本**/

 (function($) {
  /* init variables */
  luminateExtend({
    apiKey: 'Key', 
    path: {
      nonsecure: 'http://mywebsite.com', 
      secure: 'https://mywebsite.com'
    }

  });

 $(function() {
$('#NextStepForm').click( function(e) {
     if ($('input[type=email]').val().length > 0) {
         e.preventDefault();
        $('input[type=email]').fadeOut(1000);
    $('#NextStepForm').hide();
    $('input[type=text]').fadeIn(1000).removeClass('hidden');
    $('#ACTION_SUBMIT_SURVEY_RESPONSE').removeClass('hidden');

    }
});

    /* UI handlers for the Survey example */
    if($('.survey-form').length > 0) {
      $('.survey-form').submit(function() {
        window.scrollTo(0, 0);
        $(this).hide();
        $(this).before('<div class="well survey-loading">' + 
                         'Processing...' + 
                       '</div>');
      });
    }

    /* handle the Survey form submission */
    /* if the Survey is submitted succesfully, display a thank you message */
    /* if there is an error, display it inline */
    window.submitSurveyCallback = {
      error: function(data) {
        $('#survey-errors').remove();
        $('.survey-form .form-group .alert').remove();

        $('.survey-form').prepend('<div id="survey-errors">' + 
                                      '<div class="alert alert-danger">' + 
                                        data.errorResponse.message + 
                                      '</div>' + 
                                    '</div>');

        $('.survey-loading').remove();
        $('.survey-form').show();
      }, 
      success: function(data) {
        $('#survey-errors').remove();
        $('.survey-form .form-group .survey-alert-wrap').remove();

        if(data.submitSurveyResponse.success == 'false') {
            $('input[type=text]').hide();
            $('#ACTION_SUBMIT_SURVEY_RESPONSE').hide();
            $('#cons_email').show().select();
            $('#NextStepForm').show();
          $('.survey-form').prepend('<div id="survey-errors">' + 
                                      '<div class="alert alert-danger">' + 
                                        'There was an error with your submission. Please try again.' + 
                                      '</div>' + 
                                    '</div>');

          var surveyErrors = luminateExtend.utils.ensureArray(data.submitSurveyResponse.errors);
          $.each(surveyErrors, function() {
            if(this.errorField) {
              $('input[email="' + this.errorField + '"]').closest('.form-group')
                                                        .prepend('<div class="col-sm-12 survey-alert-wrap">' + 
                                                                    '<div class="alert alert-danger">' +
                                                                     this.errorMessage + 
                                                                   '</div>' + 
                                                                 '</div>');
            }
          });

          $('.survey-loading').remove();
          $('.survey-form').show();
        }
        else {
          $('.survey-loading').remove();
          $('.survey-form').before('<div class="alert alert-success">' + 
                                 '<p>Thanks for joining. You should receive your first issue of the e-newsletter shortly.</p>' + 
                                     '</div>');
        }
      }
    };
    /* bind any forms with the "luminateApi" class */
    luminateExtend.api.bind();
  });
})(jQuery);
/*******下面是html*******/

<div id="quickregbox" class="container-fluid">
<div class="form-group row">
    <div class="col-sm-9">
        <form data-toggle="validator" class="form-inline luminateApi survey-form" action="#" method="POST" data-luminateapi='{"callback": "submitSurveyCallback", "requiresAuth": "true"}'><input name="method" type="hidden" value="submitSurvey" />
            <input id="method" name="method" type="hidden" value="submitSurvey" />
            <input name="cons_email_opt_in" type="hidden" value="true" />
            <span style="display: none;">
            <input id="denySubmit" name="denySubmit" type="text" />Please leave this field empty</span>

                <div class="form-group row center-block">

                    <div class="consemaildiv form-group has-feedback">
                        <div class="col-xs-2">
                        <label for="cons_email" class="sr-only"></label>
                        <input id="cons_email" class="form-control margin-bottom border-radius padding-right" placeholder="Email Address" name="cons_email" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$" type="email" data-error="Please enter a valid email address" required maxlength="255"/>
                        <!-- <div class="help-block with-errors helpBlockWidth"></div>  help-block -->
                        </div><!-- column -->
                        <div class="col-xs-3">
                        <button id="NextStepForm" class="btn btn-primary" type="button">></button>
                    </div><!-- column -->
                    </div> <!-- form-group consemaildiv-->

                    <div class="form-group consnamediv">

                            <label for="cons_first_name" class="sr-only"></label>
                            <input id="cons_first_name" class="form-control margin-bottom margin-top hidden border-radius name-width" placeholder="First Name" name="cons_first_name" type="text" maxlength="50"/>
                            <label for="cons_last_name" class="sr-only"></label>
                            <input id="cons_last_name" class="lnameMarginTop form-control margin-bottom hidden border-radius name-width" placeholder="Last Name" name="cons_last_name" type="text" maxlength="50"/>
                            <button id="ACTION_SUBMIT_SURVEY_RESPONSE" class="btn btn-primary hidden" type="submit">></button>
                        </div> <!-- column consnamediv-->

                </div><!-- form-group -->

        </form> <!-- form end -->

</div> <!-- column -->

请将此字段留空
>
>


/**结束html**/

将代码分解为多个函数可以使您受益匪浅。这将使代码更易于理解,并且您可以重用代码。确保您了解闭包,尤其是嵌套函数,以及它们如何影响变量作用域:另外