<form id="sender">
<input type="hidden" id="article" value="ID товара">
<input type="text" id="quantuty" value="количество штук">
<input type="button" id="send_to_cart">
</form>
...
<script src="//code.jquery.com/jquery-1.11.1.js"></script>
<script src="/media/js/jquery.form.min.js"></script>
<form id="form" action="/cart/add" method="post">
<input type="hidden" id="article_id" value="15>" />
<input type="submit" value="В корзину" />
</form>
$(document).ready(function() {
$('#form').submit(function(e) {
e.preventDefault();
$(this).ajaxSubmit(options);
return false;
});
});
return false;
<form id="form" action="/cart/add" method="post">
<input type="hidden" value="15>" name="articleId" />
<button type="submit">В корзину</button>
</form>
$(function(){
$('#form').submit(function(e) {
var $this = $(this);
var data = {};
$this.find('input').each(function(){
var $el = $(this);
var key = $el.attr('name');
if(key)
data[key] = $el.val();
});
$.post($this.attr('action'),data)
.done(function(r){
console.log('good call back');
})
.fail(function(r){
console.log('bad call back');
});
e.preventDefault();
return false;
});
});
jQuery.fn.extend({
myFormSubmit: function(o){
var opts = {
doneCb: function() {},
failCb: function() {}
};
opts = $.extend(opts,o);
return this.each(function(){
$(this).submit(function(e) {
var $this = $(this);
var data = {};
$this.find('input').each(function(){
var $el = $(this);
var key = $el.attr('name');
if(key)
data[key] = $el.val();
});
$.post($this.attr('action'),data)
.done(opts.doneCb)
.fail(opts.failCb);
e.preventDefault();
return false;
});
});
}
});
$(function(){
$('#form').myFormSubmit({
doneCb: function(r){
console.log('good call back');
},
failCb: function(r){
console.log('bad call back');
}
});
});
<div id="sender">
<input type="hidden" id="article" value="ID товара">
<input type="text" id="quantuty" value="количество штук">
<input type="button" onclick="SendForm();">
</div>
function SendForm() {
$.post('url/', {article: $("#article").val(), quantuty: $("#quantuty").val(), }, function (data) {
alert('Отправлено');
});
}