返回false;不工作

时间:2014-10-26 16:31:05

标签: javascript jquery ajax

我试过返回false;我已经尝试过event.preventdefault,似乎在Firfox中都没有。它在Chrome中运行得很好,但在IE或Firefox中却没有?从当前页面获取信息,通过ajax将其发送到更新脚本,然后更新数据库。如果使用firefox它会重新加载页面并且不进行任何更新。

这是按钮的代码:

  <div class="col-md-12 text-right">
<button class="btn btn-primary btn-sm" id="savebutton" onclick="editthisframily();"><span class="fa fa-lg fa-floppy-o"></span><span id="framilyeditbutton">  Update Framily </span></button>
<button class="btn btn-danger btn-sm" id="deletebutton"><span class="fa fa-lg fa-remove"></span><span id="framilydeletebutton">  Delete Framily</span></button>
</div>  



// update framily member
    // ========================

    function editthisframily() {

      return false;

        //event.preventDefault();

    var testdate = $('#ebirthday').val();

    if(testdate.length > 5 ) {

    if(moment(testdate, ["MM/DD/YYYY"]).isValid()) {
      //alert("good");
    }
    else {
      alert("date is bad");
      return;
    }}
          $('#framilyeditbutton').text(' Updating Framily. Please Wait ...');

               if($('#egender-f').is( ":checked" )) {

                  var gender = "f";
               }
               else {

                  var gender = "m";
               }

               if($('#remindertype_email').is( ":checked" )) {

                  var remindertype_email = "true";
               }
               else {

                  var remindertype_email = "false";
               }

               if($('#remindertype_sms').is( ":checked" )) {

                  var remindertype_sms = "true";
               }
               else {

                  var remindertype_sms = "false";
               }

                var myData = 'address1='+ $("#eaddress1").val()+'&address2='+$("#eaddress2").val()+'&city='+$("#ecity").val()+'&state='+$("#estate").val()+'&zipcode='+$("#ezipcode").val()+'&country='+$("#ecountry").val()+'&telephone='+$("#etelephone").val()+'&birthday='+$("#ebirthday").val()+'&gender='+gender+'&fullname='+$("#efullname").val()+'&email='+$("#eemail").val()+'&userid='+$("#userid").val()+'&relationship='+$("#erelationship").val(); //build a post data structure

               // console.log(myData);
                jQuery.ajax({
                type: "POST", // HTTP method POST or GET
                url: "includes/updateframily.php", //Where to make Ajax calls
                dataType:"text", // Data type, HTML, json etc.
                data:myData, //Form variables
                success:function(response){
                    $("#responds").append(response);

                    setTimeout(function() {

                    $('#framilyeditbutton').text(' Framily Member Updated ');
                    framilyView();
                    $('#framilyeditbutton').text(' Update Framily Member ');

                    }, 3000)

                },
                error:function (xhr, ajaxOptions, thrownError){
                   // $("#FormSubmit").show(); //show submit button
                   // $("#LoadingImage").hide(); //hide loading image
                    $('#buttontext').text(' something went wrong');
                    alert(thrownError);
                }
                });
        };

1 个答案:

答案 0 :(得分:1)

您需要在内联处理程序中返回函数的值:

onclick="return editthisframily()"