我有这个功能,它在提交表格时执行。如何序列化整个表单并通过它?
function addToCart(el)
{
console.log(el.action);
$.post(el.action, { id: 'df'},
function(returnedData){
console.log(returnedData);
});
}
答案 0 :(得分:1)
您可以这样做:
var api = 'http://localhost/api';
$( "form" ).on( "submit", function(event) {
event.preventDefault();
var payload = $( this ).serializeArray();
$.post(api, payload, function(response) {
console.log("response", response);
});
});