weixin_33725272 2016-08-16 12:24 采纳率: 0%
浏览 32

使用jQuery获取发布的数据

I want to get posted data using jquery. I have implemen

Html Form

      <form  id="login_form" action="userPref.php" method="post" >

      <div hidden id="error" style="color:red; text-align:center;"   > <p> user not found  </p>   </div>
        <div class="form-group">
          <label for="usrname"><span class="glyphicon glyphicon-user "></span> User Id</label>
          <input type="text" value="" class="form-control" required="required" id="usrname" name="usrname" placeholder="Enter User Id" >
        </div>

          <button type="submit"  id="login" class="btn btn-success btn-block"><span class="glyphicon glyphicon-off"></span> Login</button>
      </form>

In userPref.php I am using php to get data but I actually want to use jquery

    var userid = <?php echo $_POST["usrname"] ?>;

I have also tried to access the form data using jquery but I was not able to access the data. Please help me.

  • 写回答

4条回答 默认 最新

  • weixin_33698823 2016-08-16 12:29
    关注

    POST data is data that is handled server side. And Javascript/jQuery is on client side. So there is no way you can read a post data using JavaScript/jQuery.

    But good way is

    var post_data= <?php echo json_encode( !empty($_POST) $_POST : array());?>;
    

    now you can access $_POST['username'];

    alert(post_data.username);
    

    so you can access all posted data in this way.

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?