验证表单和ajax

时间:2015-07-15 18:27:04

标签: ajax validation

抱歉我的英文 我想创建一个控制字段并通过ajax发送的表单,但这个解决方案对我不起作用:

var $j = jQuery.noConflict();
   $j('#feedback').validate({
  submitHandler:function(form) {
  $j.ajax({
                    url: 'form/feedback/mailer/mail_advanced_upload.php',
                    type: "POST",
                    data: $j(form).serialize(),
                    success: function(data) {
                        $j("#feedback").hide();
                        $j("#result").html(data);
                        var body = $j("body, html");
                        var top = body.scrollTop() // Get position of the body
                        if(top!=0)
                        {
                               body.animate({scrollTop :0}, '500',function(){ });
                        }
                        }
                });

  }
            });

你能帮我吗?

由于

1 个答案:

答案 0 :(得分:0)

这是html

<form name="feedback" id="feedback" action="">
            <div class="content_feed">
              <div class="f_size_16">1. Question?</div>
                <div class="content_face">
                    <ul class="ul_rating">
                    <li class="text-center">
                        <input type="radio" id="radio1" name="domanda_1" value="scarsa" data-validation="required" data-validation-help="">
                        <label for="radio1" class="scarsa"></label>
                        <p>Scarsa</p>
                    </li>
                    <li class="text-center">               
                        <input type="radio" id="radio2" name="domanda_1" value="normale">
                        <label for="radio2" class="normale"></label>
                        <p>Normale</p>
                    </li>
                    <li class="text-center">
                        <input type="radio" id="radio3" name="domanda_1" value="buona">
                        <label for="radio3" class="buona"></label>
                        <p>Buona</p>
                    </li>
                    <li class="text-center">
                        <input type="radio" id="radio4" name="domanda_1" value="ottima">
                        <label for="radio4" class="ottima"></label>
                        <p>Ottima</p>
                    </li>
                    <li class="text-center">
                        <input type="radio" id="radio5" name="domanda_1" value="eccellente">
                        <label for="radio5" class="eccellente"></label>
                        <p>Eccellente</p>
                    </li>
                    </ul>
                </div>
              </div>
              <div class="content_feed">
                <div class="f_size_16">2. Question?</div>
                <div class="content_face">
                    <ul class="ul_rating">
                    <li class="text-center">
                        <input type="radio" id="radio6" name="domanda_2" value="scarsa">
                        <label for="radio6" class="scarsa"></label>
                        <p>Scarsa</p>
                    </li>
                    <li class="text-center">               
                        <input type="radio" id="radio7" name="domanda_2" value="normale">
                        <label for="radio7" class="normale"></label>
                        <p>Normale</p>
                    </li>
                    <li class="text-center">
                        <input type="radio" id="radio8" name="domanda_2" value="buona">
                        <label for="radio8" class="buona"></label>
                        <p>Buona</p>
                    </li>
                    <li class="text-center">
                        <input type="radio" id="radio9" name="domanda_2" value="ottima">
                        <label for="radio9" class="ottima"></label>
                        <p>Ottima</p>
                    </li>
                    <li class="text-center">
                        <input type="radio" id="radio10" name="domanda_2" value="eccellente">
                        <label for="radio10" class="eccellente"></label>
                        <p>Eccellente</p>
                    </li>
                    </ul>
                </div>
              </div>
              <div class="content_feed">
                <div class="f_size_16">3. Question?</div>
                <div class="content_face">
                    <ul class="ul_rating">
                    <li class="text-center">
                        <input type="radio" id="radio11" name="domanda_3" value="scarsa">
                        <label for="radio11" class="scarsa"></label>
                        <p>Scarsa</p>
                    </li>
                    <li class="text-center">               
                        <input type="radio" id="radio12" name="domanda_3" value="normale">
                        <label for="radio12" class="normale"></label>
                        <p>Normale</p>
                    </li>
                    <li class="text-center">
                        <input type="radio" id="radio13" name="domanda_3" value="buona">
                        <label for="radio13" class="buona"></label>
                        <p>Buona</p>
                    </li>
                    <li class="text-center">
                        <input type="radio" id="radio14" name="domanda_3" value="ottima">
                        <label for="radio14" class="ottima"></label>
                        <p>Ottima</p>
                    </li>
                    <li class="text-center">
                        <input type="radio" id="radio15" name="domanda_3" value="eccellente">
                        <label for="radio15" class="eccellente"></label>
                        <p>Eccellente</p>
                    </li>
                    </ul>
                </div>
              </div>
              <div class="content_feed">
                <div class="f_size_16">4. Question?</div>
                <div class="content_face">
                    <ul class="ul_rating">
                    <li class="text-center">
                        <input type="radio" id="radio16" name="domanda_4" value="scarsa">
                        <label for="radio16" class="scarsa"></label>
                        <p>Scarsa</p>
                    </li>
                    <li class="text-center">               
                        <input type="radio" id="radio17" name="domanda_4" value="normale">
                        <label for="radio17" class="normale"></label>
                        <p>Normale</p>
                    </li>
                    <li class="text-center">
                        <input type="radio" id="radio18" name="domanda_4" value="buona">
                        <label for="radio18" class="buona"></label>
                        <p>Buona</p>
                    </li>
                    <li class="text-center">
                        <input type="radio" id="radio19" name="domanda_4" value="ottima">
                        <label for="radio19" class="ottima"></label>
                        <p>Ottima</p>
                    </li>
                    <li class="text-center">
                        <input type="radio" id="radio20" name="domanda_4" value="eccellente">
                        <label for="radio20" class="eccellente"></label>
                        <p>Eccellente</p>
                    </li>
                    </ul>
                </div>
              </div>
              <div class="content_feed">
                <div class="f_size_16">5. Question?</div>
                <div class="content_face">
                    <ul class="ul_rating">
                    <li class="text-center">
                        <input type="radio" id="radio21" name="domanda_5" value="scarsa">
                        <label for="radio21" class="scarsa"></label>
                        <p>Scarsa</p>
                    </li>
                    <li class="text-center">               
                        <input type="radio" id="radio22" name="domanda_5" value="normale">
                        <label for="radio22" class="normale"></label>
                        <p>Normale</p>
                    </li>
                    <li class="text-center">
                        <input type="radio" id="radio23" name="domanda_5" value="buona">
                        <label for="radio23" class="buona"></label>
                        <p>Buona</p>
                    </li>
                    <li class="text-center">
                        <input type="radio" id="radio24" name="domanda_5" value="ottima">
                        <label for="radio24" class="ottima"></label>
                        <p>Ottima</p>
                    </li>
                    <li class="text-center">
                        <input type="radio" id="radio25" name="domanda_5" value="eccellente">
                        <label for="radio25" class="eccellente"></label>
                        <p>Eccellente</p>
                    </li>
                    </ul>
                </div>
              </div>

              <div class="dati_feedback">
                <div class="row">
                    <div class="col-md-6">
                        <label class="label_input_style">Name *</label>
                        <input type="text" name="name" class="input_style" data-validation="required" />
                    </div>
                    <div class="col-md-6">
                        <label class="label_input_style">Surname *</label>
                        <input type="text" name="surname" class="input_style" data-validation="required"  />
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-6">
                        <label class="label_input_style">E-mail *</label>
                        <input type="text" name="email" class="input_style" data-validation="email" />
                    </div>
                    <div class="col-md-6">
                        <label class="label_input_style">phone *</label>
                        <input type="text" name="cellulare" class="input_style" data-validation="number"  />
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-6">
                        <label class="label_input_style">city *</label>
                        <input type="text" name="city" class="input_style" data-validation="required" />
                    </div>
                    <div class="col-md-6">
                        <label class="label_input_style">State *</label>
                        <input type="text" name="state" class="input_style" data-validation="required"  />
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-4 col-sm-4 col-xs-6">
                        <label class="label_input_style">Captcha *</label>
                        <input name="captcha" type="text" autocomplete="off" class="input_style_captcha"  />
                    </div>
                    <div class="col-md-8 col-sm-8 col-xs-6 mrg_top_20 text-left">
                        <div id='forminvio_captcha_errorloc' class="error_class"></div>
                        <img src="form/feedback/mailer/captcha.php" alt="" />
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12 col-sm-12 col-xs-12 mrg_top_20">
                        <p style="font-size:11px;">privacy</p>
                    </div>
                </div>
                <div class="row mrg_top_20">
                    <div class="col-md-12 col-centered"><input type="submit" value="Send feedback" class="button" /></div>
                </div>
              </div>
          </div>
          </form>