我一直在尝试使用ajax,使用php中的按钮,将点击事件链接到php函数。然而,当我点击按钮时,绝对不会发生任何事情。我不知道为什么
这是我的php代码
$(document).ready(function () {
$('#aeps').click(function () {
var printpayslips = $(this).val();
$_ajax({
type: 'POST',
url: '../print.php';
dataType: 'json',
data: {
printslip: printpayslips
},
success: function (response) {
console.log(response);
}
})
})
$('#ps').click(function () {
var paysum = $(this).val();
$_ajax({
type: 'POST',
url: 'print.php';
dataType: 'json',
data: {
printsum: paysum
},
success: function (response) {
console.log(response);
}
})
}) $('#create').click(function () {
var cr = $(this).val();
$_ajax({
type: 'POST',
url: 'print.php';
dataType: 'json',
data: {
create: cr
},
success: function (response) {
console.log(response);
}
})
})
})
使用Chrome运行代码会有所帮助,因为开发人员控制台会告诉你代码在哪里失效。
需要注意的一些事项:
除非您编写了一个名为$_ajax
的特定ajax函数,否则jQuery的ajax函数就是$.ajax
。此外,您编写的每一行url:
都以分号结尾,其中应该以逗号结尾。