ajax post

时间:2017-12-31 11:46:47

标签: javascript php jquery ajax

我在这个主题上发现了很多问题,但无法弄清楚我做错了什么。

我尝试将数据传递给新的PHP页面,但我总是得到NULL。

这是我的JS代码:

submitHandler: function() {
$.ajax({
        method: 'POST',
        url: 'newPhp.php',
        data: { name: "13" },
        success: function(name) {
            console.log(name); // is displayed correctly
            window.location.replace("newPhp.php");
        },
        error: function(xhr, ajaxOptions, thrownError) {
            alert(xhr.status);
            alert(thrownError);
        } //no error occurs for me
    });
}

我的PHP文件就是这样做的:

$passedName = $_POST["name"];
var_dump($passedName);

我想使用它将数据从输入表单传递到服务器,服务器发送确认邮件。

0 个答案:

没有答案
相关问题