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 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据