Created
March 12, 2014 12:45
-
-
Save yurifrl/9506209 to your computer and use it in GitHub Desktop.
ajax update 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 ids = undefined; | |
$(document).ready(function () { | |
var $form = $("form.edit_product"); | |
var form_action = $form.attr("action"); | |
var product_name_id = form_action.split('/')[3]; | |
var option_types_url = window.location.protocol + "//" + window.location.host + "/" + 'api/products/' + product_name_id; | |
$form.submit(function(e, data){ | |
e.preventDefault(); | |
$.ajax({ | |
type: "POST", | |
dataType: "json", | |
url: form_action, | |
method: "PUT", | |
data: {product: {option_type_ids: $("#product_option_type_ids").val()}, utf8: "✓", authenticity_token: encodeURIComponent($('#authenticity-token').val()), variant_page: "true"} | |
}).fail(function(data){ | |
alert("FAIL"); | |
}).success(function(data){ | |
console.log(data); | |
$.getJSON(option_types_url, null ).done(function(json) { | |
$.each(json.option_types, function(index, value) { | |
console.log(value.id); | |
}); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment