dongqing904999 2019-04-11 17:23
浏览 76
已采纳

我应该用什么来从PHP中的字段userid和密码中获取值? 我得到一个带有给定代码的空字符串

I have to file main.html(main file) and login.html(contetns only form without html document means body and html tags) and use the .load() method of jquery to load the form from login.html to the main.html and submit to the login.php. And when i try to fetch the value of the input field in php it just give a empty string or say nothing. I don't want to use this method only. So is it wrong or not possible or is there any other php method which is able to fetch these fields.

main.html

    <html>
    <head>
        <title>My Media</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <!--script src="https://code.jquery.com/jquery-1.11.1.min.js">   </script>
        <script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/jquery.validate.min.js"></script>
        <script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0    /additional-methods.min.js"></script-->

        <script src="jquery.js"></script>
        <script src="javascript.js"></script>
        <link rel="stylesheet" href="css.css">
    </head>
    <body>
        <div id="nav-placeholder" name="nav-placeholder"></div>
        <div id="body" name="body">
        </div>

    </body>
</html>

login.html

<div id="loginPage">
    <br><h1>My Media</h1><br><br><br>
    <form id="form1" name="form1" method="post" onsubmit="return validate()" action="login.php">
        UserId:<br><input id="userid" name="userid" type="text" required><br>
        Password:<br><input id="password" name="password" type="password" required><br>
        <input id="Login" name="Login" type="submit" value="login">
    </form> 
</div>

jquery.js

$(function(){
    var page="home";
                $("#nav-placeholder").load("menu.html");    
                $("#body").load("home.html")

    $("body").on("click","#home",function(){
        if(page!="home"){
        $("#body").empty();//after("<h3><u>Some appended text.</u></h3>");
        $("#body").load("home.html");
        page="home";}
    }); 

    $("body").on("click","#help",function(){
    if(page!="help"){
        $("#body").empty();//after("<h3><u>Some appended text.</u></h3>");
        $("#body").load("help.html");
        page="help";}
    }); 

    $("body").on("click","#login",function(){
        if(page!="login"){
        $("#body").empty();//after("<h3><u>Some appended text.</u></h3>");
        $("#body").load("login.html");
        page="login";}
    }); 

    $("body").on("click","#register",function(){
        if(page!="register"){
        $("#body").empty();//after("<h3><u>Some appended text.</u></h3>");
        $("#body").load("register.html");
        login="register";}
    });

    $("body").on("click","#about",function(){
        if(page!="home"){
        $("#body").empty();//after("<h3><u>Some appended text.</u></h3>");
        $("#body").load("about.html");
        page="about";}  
    });

    $("body").on("click","#bottom",function(){
        if(page!="home"){
        $("#body").empty();//after("<h3><u>Some appended text.</u></h3>");
        $("#body").focus("#contacts");
        page="about";}  
    });

});

login.php

<?php

$usrname = $_POST["userid"];
$pass = $_POST["password"];

echo $usrname."--".$pass;
?>

what should a use?

  • 写回答

1条回答 默认 最新

  • dongpo2002 2019-04-11 17:53
    关注

    @Ashitosh Kamble

    You should send the form values in a json format using an ajax call when the user clicks on login.

    var userid = $('#userid').val();
    var password = $('#password').val();
    
    var data = {
      "user_id":userid,
      "homeTown": password
    }
    
    $("#login").click(function(event){
           $.ajax( {
                      url:'login.php',
                      type:'post',
                      success:function(data) {
                         // Allow Login
                      }
                   });
                });
    
    

    Hope it works!!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?