douhan0562 2016-05-09 20:46
浏览 66

运行时的表单帖子不起作用 - jQuery / AJAX / Post

I am trying to post a data on run time and I want to see this data same time. But I don't understand clearly how can I do. I think my problem is I could not choose the element correctly. What is wrong on my code ? Thanks all from now :)

My Error is : Notice: Undefined index: username in C:\wamp\www\eva\check.php on line 3

Line 3 : echo $username = $_POST["username"];

form.php

<html>
<head>
    <title>jQuery</title>
</head>
<body>
    <div class="formwrapper">
        <form method="post" action="" name="form">
            <input type="text" id="rname" class="inputa" name="uname" placeholder="Username">
            <div id="feedback"></div>
        </form>
    </div>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
    <script src="myScript.js"></script>
</body>
</html>

check.php

<?php

    echo $username = $_POST["uname"];

?>

myScript.js

$(document).ready(function() {

    $("#feedback").load("check.php").show();

    $("#rname").keyup(function() {

        $.post("check.php", { username: uname.value },
        function(result){

            $("#feedback").html(result).show();

        })

    });

});
  • 写回答

1条回答 默认 最新

  • doulu5109 2016-05-09 20:50
    关注

    You are POSTing the value as username and trying to retrieve it as uname. Rename your key in PHP:

    $username = $_POST['username']
    

    It's probably also a good idea to check if the value exists and return a nice error message instead of letting your code fail.

    评论

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应