Created
August 9, 2016 04:09
-
-
Save d30jeff/73d26189b1a1e735fa6300346b6ebc9d to your computer and use it in GitHub Desktop.
What is this front end bullshit?
This file contains hidden or 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
// Just to make life easier. | |
var common = { | |
ajaxPut: function(url, body) { | |
return $.ajax({ | |
url: url, | |
type: 'PUT', | |
dataType: 'json', | |
data: body | |
}); | |
}, | |
}; | |
// Form Snippet | |
<div class='col-sm-3'> | |
<select id='device_parameter_set_id' class='form-control' required> | |
<option value='0'>Device Parameter Set</option> | |
</select> | |
</div> | |
// Append to options | |
common.ajaxGet('host/awesome/uri')) | |
.always(function(resp) { | |
$.each(JSON.parse(resp.responseText), function(key, value) { | |
$("#device_parameter_set_id").append($('<option></option>').val(value.id).text(value.name)); | |
}); | |
}); | |
// Ajax | |
$("#devicePut").on('submit', function(evt) { | |
evt.preventDefault(); | |
common.ajaxPut('host/put/URI', { | |
device_param: parseInt($("#device_parameter_set_id").val()); | |
}) | |
.done(function(resp, text, http) { | |
if (resp) { | |
alert(resp.responseText); | |
} else { | |
alert(text.status); | |
} | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment