Created
March 12, 2014 19:49
-
-
Save yurifrl/9514894 to your computer and use it in GitHub Desktop.
form submit ajax spree rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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