window.onload = function() {
}
Alternatively, we can use the jQuery syntax:
$(document).ready(function() {
});
$('#new-option-form').on("submit", function(event) {
}
event.preventDefault();
var new_option = $('#new-option-field')[0].value;
if (new_option.length > 0) {
}
if (new_option.length > 0) {
submitNewOption(new_option);
}
var submitNewOption = function(option) {
}
var submitNewOption = function(option) {
$.ajax({
method: "post",
url: "/new_option",
data: { option: option }
});
}
9. Add a function on the end that specifies what happens when the request gets successfully completed
$.ajax({
method: "post",
url: "/new_option",
data: { option: option }
}).success(function() {
// do stuff here
});
9. Fill out the function that specifies what happens upon a successful completion of the ajax request.
This will involve using JS to add elements to the page for the new color option, since we aren't refreshing it.
$.ajax({
method: "post",
url: "/new_option",
data: { option: option }
}).success(function() {
alert("Success!");
$('#new-vote-form').prepend(
"<label for='choice'><input type='radio' name='choice' value="
+ option
+ ">"
+ vote_option
+ "</label><br />"
);
$('#votes-count').append(
"<tr>"
+ "<td>" + option + "</td>"
+ "<td>0</td>"
+ "</tr>"
);
});