Ajax onclick 不起作用
Ajax onclick wont work
我有一个带有复选框的表单,单击此复选框时,一些 ajax 应该提交。
它不起作用,我已经盯着它看了好几个小时了。我希望有人能告诉我为什么它不起作用。提前致谢。代码如下
<td>
<form method="POST" action="" class="insertLike">
<input type="checkbox" class="safeBetCheck" name="safeBet" style="margin-left:auto; margin-right:auto;">
</td>
<input type="hidden" value="<?php echo$preBetFeed['id'];?>">
</form>
var check = $('.safeBetCheck');
var formLike = $('.insertLike').serialize();
$('input').on('click',function(){
if (check.is(':checked')){
$.ajax({
type: "POST",
url: "trusted.php",
data: formData,
success: function(formLike){
alert('yeah!');
}
});
}
else {
alert('no');
}
});
将formdata
替换为formLike
var check = $('.safeBetCheck');
var formLike = $('.insertLike').serialize();
$('input').on('click',function(){
if (check.is(':checked')){
$.ajax({
type: "POST",
url: "trusted.php",
data: formLike,
success: function(formLike){
alert('yeah!');
}
});
}
else{
alert('no');
}
});
我有一个带有复选框的表单,单击此复选框时,一些 ajax 应该提交。
它不起作用,我已经盯着它看了好几个小时了。我希望有人能告诉我为什么它不起作用。提前致谢。代码如下
<td>
<form method="POST" action="" class="insertLike">
<input type="checkbox" class="safeBetCheck" name="safeBet" style="margin-left:auto; margin-right:auto;">
</td>
<input type="hidden" value="<?php echo$preBetFeed['id'];?>">
</form>
var check = $('.safeBetCheck');
var formLike = $('.insertLike').serialize();
$('input').on('click',function(){
if (check.is(':checked')){
$.ajax({
type: "POST",
url: "trusted.php",
data: formData,
success: function(formLike){
alert('yeah!');
}
});
}
else {
alert('no');
}
});
将formdata
替换为formLike
var check = $('.safeBetCheck');
var formLike = $('.insertLike').serialize();
$('input').on('click',function(){
if (check.is(':checked')){
$.ajax({
type: "POST",
url: "trusted.php",
data: formLike,
success: function(formLike){
alert('yeah!');
}
});
}
else{
alert('no');
}
});