我有一个我发送的表单,目前它使用类似.button类的p标记。出于某种原因,我没有得到任何回复而没有在我的chrome dev工具的网络标签中提交?可以帮忙吗?
$(".button-like").each(function () {
$(this).click(function () {
var $thisItem = $(this);
var $parent = $thisItem.parent(".forms");
$parent.submit(function () {
var data = {
"action": "like"
};
data = $parent.serialize() + "&" + $.param(data);
var itemId = $parent.find('input.id').val();
$.ajax({
type: "POST",
url: "/actions/",
data: data,
success: function (data) {
console.log('Like submitted successfully sent');
$('body').addClass('liked');
}
});
return false;
});
});
});
谢谢, 标记
答案 0 :(得分:0)
$(".button-like").each(function () {
$(this).click(function () {
var $thisItem = $(this);
var $parent = $thisItem.parent(".forms");
$parent.submit(function () {
var data = {
"action": "like"
};
data = $parent.serialize() + "&" + $.param(data);
var itemId = $parent.find('input.id').val();
$.ajax({
type: "POST",
url: "/actions/",
data: data,
success: function (data) {
console.log('Like submitted successfully sent');
$('body').addClass('liked');
}
});
return false;
}).submit();
});
});
这将在设置后立即触发提交。但我认为你想要做的是:
$(".button-like").each(function () {
var $thisItem = $(this);
var $parent = $thisItem.parent(".forms");
$parent.submit(function () {
var data = {
"action": "like"
};
data = $parent.serialize() + "&" + $.param(data);
var itemId = $parent.find('input.id').val();
$.ajax({
type: "POST",
url: "/actions/",
data: data,
success: function (data) {
console.log('Like submitted successfully sent');
$('body').addClass('liked');
}
});
return false;
});
$thisItem.click(function () {
$parent.submit();
});
});