3

我发布的脚本工作正常,它只是在页面加载时在后台执行我的 php 代码。我不能做的是在按下提交按钮后在后台启动 php。我试图在正文,但我不知道如何将它与 ajax 链接.. 怎么办?谢谢!

<html>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>

<script type="text/javascript">
  $(document).ready(function() {
    $.ajax({
        url: 'trial.php',
        beforeSend: function() {
            // you could also put a spinner img or whatever here too..
            $("#myStatusDiv").html("started..");
        },
        success: function(result) {
            $("#myStatusDiv").html(result);
        }
    });
  });
</script>

</head>
<body>

</body>                                                                                                             

</body>                                     
</html>
4

1 回答 1

3

当文档准备好加载时,您当前正在执行代码。您应该将此代码添加到按钮单击事件中。

所以代替这个

$(document).ready(function() {
    //your code
});

这样做

$(document).ready(function() {
    $('#buttonid').click(function() {
        //your code
    });
});
于 2012-04-15T21:15:11.823 回答