English 中文(简体)
表单不打印任何信息
原标题:Form not printing anything

我尽力复制文件,让用户在信息输入用户和密码文本框时看到显示的信息。但是,信息显示没有发生。

以下是我的ajax. html文件:

<html>
<head>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $("#button").click(function(){
        var sendu = $("#username").val();
        var sendp = $("#pw").val();
        $.ajax({
            type: "POST",
            url: "ajax.php",
            data: "username="+sendu+"&password="+sendp,
            dataType: "json",
            success: function(msg, string, jqXHR){
                    $("#result").html(msg+string+jqXHR);
                }
            });

    });
});


</script>
</head>
<body>
<input type="text" id="username" name="username" /><br />
<input type="password" id="pw" name="pw" /><p>
<input type="button" id="button" value="Submit" />
<p><div id="result"></div>
</body>
</html>

这是我的ajax.php文件:

<?php

$name = $_REQUEST["username"];
$pw = $_REQUEST["pw"];

$list = array( name =>$name,  password =>$pw);

$c = json_encode($list);

echo $c;

?>
问题回答
$("#result").html(msg.name + msg.password);

变动 变动

$pw = $_REQUEST["pw"];

$pw = $_REQUEST["password"];

You are sending variables with ajax... and you have assigned 至 variable 至 be password, not pw (which is the name of your input).

And don t forget 至 actually write something inside the inputs so you can receive something back also.

$(document).ready(function(){
    $("#button").on( click , function(){
        var sendu = $("#username").val(),
            sendp = $("#pw").val();
        $.ajax({
            type: "POST",
            url: "ajax.php",
            data: {username : sendu, password : sendp},
            dataType: "json",
            success: function(data){
                 $("#result").html(data.name).prepend(data.password);
            }
        });
    });
});

PHP 惠PHP

<?php
    $name = $_POST["username"];
    $pw = $_POST["password"];
    $list = array( name =>$name,  password =>$pw);

    echo json_encode($list);
?>




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签