发布ajax请求没有达到php

时间:2015-08-29 06:57:25

标签: php jquery ajax

我正在尝试用jquery学习ajax,但我的脚本似乎不起作用 我使用该表单来查看script.php文件是否有任何问题,但它工作正常。 当我点击sendAjax按钮时没有任何反应。我检查firefox上的dev工具中的网络选项卡,似乎没有发送任何内容。 我也尝试发送数据json样式,但也没有工作{'data':'Data'} 即使我在php脚本上回应一些东西也行不通。 我认为这只是一个愚蠢的错误,但因为这是我的第一个ajax脚本,我很难找到它

这是我的脚本。 index.html jquery脚本

$(document).ready(function () {
    $("#sendAjax").click(function () {

        $.ajax({
            type: 'POST',
            url: "script.php",
            cache: false,
            data: {
                dataStr: 'Content'
            },
            succes: function (response) {
                alert("merge");
            }


        });
    });
});

index.html html

<div id='container'>
    <form action='script.php' method='POST'>
        <input type='text' name='username' id='username' placeholder="name">
        <input type='password' name='password' id='password' placeholder="password">
        <input type="submit" name='button' value="SendForm" id='button'>
    </form>
    <button id='sendAjax'>Send</button>
</div>    

的script.php

<?php
    if(isset($_POST)){
        var_dump($_POST);
    }

1 个答案:

答案 0 :(得分:0)

succes: function (response) {
  alert("merge");
}

更改为

success: function (response) {
   alert("merge");
}