PHP,Jquery ajax没有将表单作为可识别的$ _POST传递

jpm*_*yob 0 php ajax jquery

使用.ajax()时,jQuery似乎没有传递表单变量或http POST操作

做一个var_dump($ _POST); 导致一个空数组.

建议?我做错了什么......这是一个简单的概念 - 有人发布了一个类似的Q,但没有人回复,他的解决方案是在表单中添加一个id,我已经有了这个,所以它没有解决我的问题.

目前我正在查看firebug中的返回页面内容 - 我还没有做任何事情,因为我无法将数据提供给服务器......(首先要做的事情).

我的HTML

<script type="text/javascript">
$( document ).ready( function(){
    $( "#myform" ).submit( function () {
        $.ajax({
            type: "POST",
            dataType: "html",
            cache: false,
            url: "x.php",
            success: function( data ){              
                //...tell user there was success...
            },
            error: function( data ){
                //...tell user thre was a problem...
            }
        });
        return false;
    });     
});
</script>

<form name="myform" id="myform" action="" method="POST">
    <label for="name" id="name_label">x: </label>
    <input type="text" name="x" id="x" size="30" value=""/> 
    <input type="submit" name="submit" value="Submit"> 
</form>
<div id="results"><div>
Run Code Online (Sandbox Code Playgroud)

这是(x.php)PHP代码 - 非常简单的概念证明......

<?php
var_dump( $_GET );
var_dump( $_POST );
var_dump( $_REQUEST );
?>
Run Code Online (Sandbox Code Playgroud)

响应看起来像这样

array(0) {}
array(0) {}
array(1) {
  ["PHPSESSID"]=>
  string(26) "e1j18j..."
}
Run Code Online (Sandbox Code Playgroud)

Mus*_*usa 5

你没有data在ajax调用中传递任何帖子,试试

    $.ajax({
        type: "POST",
        dataType: "html",
        cache: false,
        url: "x.php",
        data: $(this).serialize(),
        success: function( data ){              
            //...tell user there was success...
        },
        error: function( data ){
            //...tell user thre was a problem...
        }
    });
Run Code Online (Sandbox Code Playgroud)