Skip to content

Instantly share code, notes, and snippets.

@yurifrl
Created March 12, 2014 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yurifrl/9514894 to your computer and use it in GitHub Desktop.
Save yurifrl/9514894 to your computer and use it in GitHub Desktop.
form submit ajax spree rails
var $form = $("form.edit_product");
var form_action = $form.attr("action");
var product_name_id = form_action.split('/')[3];
var api_url = window.location.protocol + "//" + window.location.host + '/api/';
$form.submit(function (e, data) {
e.preventDefault();
$.ajax({
url: form_action,
dataType: "json",
type: "post",
method: "PUT",
data: {
product: {
option_type_ids: $("#product_option_type_ids").val()
},
authenticity_token: $('[name=authenticity_token]').val()
}
}).fail(function (data) {
console.log("FAIL");
}).success(function (data) {
console.log("SUCCESS");
// TODO Tell the user that this action will override the changes that he has done
start();
//console.log(data);
});
});// Form Submit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment