我的jquery-1.7.2.min.js在ajax调用中加载了两次

时间:2014-07-09 13:04:58

标签: jquery ajax asp.net-mvc

任何人都可以帮我解决以下问题

我正在使用jquery ajax调用来绑定数据。函数工作正常,但我的js文件加载两次,所以它来到原始位置

在mvc 4.0上工作

 $(window).load(function () {
      $('#btnSubmitss').click(function () {
          var folionumber = $('#txtfolionumber').val();
          var url = "/Account/CheckFolioNumber";
          if (!$('#chk_chk_SecurityAnswer').is(':checked')) {
              $.ajax({
                  type: "POST",
                  url: url,
                  data: { folinumber: folionumber },
                  dataType: "json",
                  success: function (returndata) {
                      if (returndata.ok) {                        
                          var Arrdataval = returndata.data.split('-');                         
                          $('#divfolioDetails').hide();
                          $('#divforgotsecQues').hide();
                          $('#divupdaetForgotdetails').hide();
                          $('#divforgotUserThank').hide();
                          $('#pmsg').html('');
                          $('#pmsg').html(Arrdataval[0]);                         
                          $('#divforgotFolio').show();
                          $('#hdtxtSecretanswer').val(Arrdataval[1]);
                      }
                      return true;
                  }
//here it is loading
              });          }
    enter code here
      });
      });

1 个答案:

答案 0 :(得分:0)

Please check this code.You should use unbind before binding click

 $(window).load(function () {
        $('#btnSubmitss').unbind( "click" ).bind( "click", function( event ) {
            var folionumber = $('#txtfolionumber').val();
            var url = "/Account/CheckFolioNumber";
            if (!$('#chk_chk_SecurityAnswer').is(':checked')) {
                $.ajax({
                    type: "POST",
                    url: url,
                    data: { folinumber: folionumber },
                    dataType: "json",
                    success: function (returndata) {
                        if (returndata.ok) {                        
                            var Arrdataval = returndata.data.split('-');                         
                            $('#divfolioDetails').hide();
                            $('#divforgotsecQues').hide();
                            $('#divupdaetForgotdetails').hide();
                            $('#divforgotUserThank').hide();
                            $('#pmsg').html('');
                            $('#pmsg').html(Arrdataval[0]);                         
                            $('#divforgotFolio').show();
                            $('#hdtxtSecretanswer').val(Arrdataval[1]);
                        }
                        return true;
                    }
                    //here it is loading
                });          }

        });
    });