SOURCE

console 命令行工具 X clear

                    
>
console
 $(document).ready(function(){
        $("#button").click(function(){
            $.post("index.php",{username:$("#username").val(),content:$("#content").val()},function(data,textStatus){
                 $("#responseText").html("用户名:"+data.username+"<br/>留言内容:"+data.content);     // 将用户提交的用户名与留言内容显示
            },"json");
        })
    })

   
 <?php
    if(!empty($_POST['username']) && !empty($_POST['content'])){
        $username = $_POST['username'];
        $content = $_POST['content'];
        $dataArray = array("username"=>$username,"content"=>$content);
        $jsonStr = json_encode($dataArray);
        echo $jsonStr;
    }
?>

<form name="form" action="">
    用户名:<input type="text" id="username" /><br/><br/>
    内容:<textarea id="content"></textarea><br/><br/>
    <input type="button" id="button" value="提交"/><br/><br/>
    <div id="responseText"></div>
</form>

本项目引用的自定义外部资源