jQuery重置表单成功错误

时间:2011-09-06 13:57:15

标签: javascript jquery

我使用ajax提交表单,我需要做的是在成功提交后重置表单。但是,正在发生的事情是,一旦用户提交,表单就会被清除。我试图将代码放在Success,Complete中,但即使用户收到错误消息,它仍会保持重置状态。我只需要在else语句后重置。即;用户收到成功消息。我怎么能纠正这个。谢谢

$.ajax({
      type: "POST",
      url: "boxrtrvajax.php",
      cache: false,
      data: send,
      success: function (data) {
      if (data == 'No data'){
      $('#brtv-result').addClass("result_msg").html('Please fill in all fields');
      }

      else

      //location.reload(true);
      $('#brtv-result').addClass("result_msg").html("You have successfully retrieved: "+data).fadeIn(4000).delay(4000).fadeOut(4000);
      $("#BRV-brtrv-slider").val(0).slider("refresh");
      $("input[type='radio']").attr("checked",false).checkboxradio("refresh");
      var myselect = $("select#BRV-brtrv-department");
      myselect[0].selectedIndex = 0;
      myselect.selectmenu("refresh");
      var myselect = $("select#BRV-brtrv-address");
      myselect[0].selectedIndex = 0;
      myselect.selectmenu("refresh");
      },

      error:function (xhr, ajaxOptions, thrownError){
      jAlert('There was an exception thrown somewhere');
      alert(xhr.status);
      alert(thrownError);
     }
   });

1 个答案:

答案 0 :(得分:1)

你的else语句周围没有括号,所以无论什么

它都能完成代码
 if (data == 'No data')
      $('#brtv-result').addClass("result_msg").html('Please fill in all fields');
 else
 {
      //location.reload(true);
      $('#brtv-result').addClass("result_msg").html("You have successfully retrieved: "+data).fadeIn(4000).delay(4000).fadeOut(4000);
      $("#BRV-brtrv-slider").val(0).slider("refresh");
      $("input[type='radio']").attr("checked",false).checkboxradio("refresh");
      var myselect = $("select#BRV-brtrv-department");
      myselect[0].selectedIndex = 0;
      myselect.selectmenu("refresh");
      var myselect = $("select#BRV-brtrv-address");
      myselect[0].selectedIndex = 0;
      myselect.selectmenu("refresh");
  }