dongsha9208 2017-02-16 07:52
浏览 64
已采纳

我已经尝试使用ajax调用我的PHP函数,但我不知道它的代码错误是什么不起作用

 !-- Main Page Starts Here -->
  <section class="container">
    <div class="row">
      <div class="centerlogin">
         <div class="frmlogin">
          <form role="form" name="signin" id="signin" method="post" action="#">
          <div class="headtab"><h3>Login</h3></div>
          <ul>    
          <li><i class="glyphicon glyphicon-user"></i>&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" id="email" name="username" class="usern" placeholder="Enter Username"></li>
          <li><i class="glyphicon glyphicon-lock">&nbsp;</i><input type="password" id="pwd" name="password" class="passn" placeholder="Enter Password"></li>
          <li><button class="subn" id="btnSubmit">Login</button></li>
         </ul>
         </form>
        </div>

      </div>

    </div>
  </section>
  <!-- Main Page Ends Here --> 

the above is my login form.

and below is my ajax call

//ajax calls start below
$(document).ready(function () {
        $("#btnSubmit").click(function (e) {
          e.preventDefault();
        var email = $("#email").val();
        var password = $("#pwd").val();
        var pwd = $.md5(password);
        auth(email, pwd);
        });
        });

        //authenticate function to make ajax call
        function auth(email, pwd) {
        $.ajax
        ({
        type: "POST",
        url: "https://localhost/main/web/sign-in",
        dataType: 'json',
        type : "POST",
        data: { email: email,pwd: pwd },
        success: function (r) {
          //console.log(r);
          if(r.status == '0')
          {
            var sk=r.sk;
            $.ajax({
                type: "POST",
                url: "http://localhost/main/secret/signin.php",
                type : "POST",
                data: { sk:sk},
                success: function(r)
                {
                  if(r == '0')
                  {
                     window.location.href = "http://localhost/main/index.php";
                  }
                  else
                  {
                    window.location.href = "http://localhost/main/login.php";
                    alert('Something Went Wrong.Please Try Again!');
                  }
                }

              });
          }
          else if(r.status == '401')
          {
            alert("Incorrect Email/Password");
            $("#signin")[0].reset();
          }
          else
          {
            alert("User Doesn't exist");
            $("#signin")[0].reset();
          }
        return false;
        }

        
      });
    } 
   

I dont know whats wrong with my code even the code its not working, it is not even showing the alerts on form blank inputs and form gets reload after clicking login button,Please help me stuck very badly.

</div>
  • 写回答

3条回答 默认 最新

  • ds355020 2017-02-16 08:06
    关注

    Type property in Ajax call is defined twice.

    Please use debugging tool, such as Firebug to debug xhr requests to understand if they are being sent or not. You can also view the responses of those requests which might hint errors.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)