我已经编写了这个函数来调用 php 脚本,但它不起作用
function finalfun(id) {
$.ajax({
data: {
'id': id
},
url: '/delete.php',
method: 'POST', // or GET
success: function (msg) {
alert(msg);
}
});
这是我的 php 脚本 delete.php
<?php
if(isset($_POST['id']))
{
echo ($_POST['id']);
}
else
{
echo "Id not found";
}
?>
我已经在 .php 文件中编写了 Finalfun(),所以这是一个问题
最佳答案
测试.html:
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script>
finalfun(5);
function finalfun(id) {
$.ajax({
data: {
'id': id
},
url: 'delete.php',
method: 'POST', // or GET
success: function (msg) {
alert(msg);
}
});
}
</script>
删除.php:
<?php
echo $_POST['id'];
?>
关于javascript - 如何在单击按钮时从 javascript 函数调用 ajax?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34082514/