gpt4 book ai didi

php - 提交按钮后的ajax后台进程

转载 作者:搜寻专家 更新时间:2023-10-31 20:49:01 26 4
gpt4 key购买 nike

我发布的脚本工作正常,它只是在页面加载时在后台执行我的 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>

最佳答案

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

所以不是这个:

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

这样做:

$(document).ready(function() {
$('#buttonid').click(function() {
//your code
});
});

关于php - 提交按钮后的ajax后台进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10166155/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com