Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def create
- @my_thing = MyThing.create(params[:my_thing])
- respond_to do |format|
- format.json { @my_thing.to_json }
- end
- end
- $(document).ready(function() {
- var $list = $('#list'),
- $form = $('#my_form');
- $form.bind('submit', function(event) {
- event.preventDefault();
- $.ajax({
- url: $form.attr('action')+'.json',
- type: 'POST',
- dataType: 'json',
- data: $form.serialize(),
- success: function(json) {
- var obj = json['my_model_name'];
- $list.append('<li>'+obj['name']+'</li>');
- $form.find(':input').each(function() {
- switch(this.type) {
- case 'password':
- case 'select-multiple':
- case 'select-one':
- case 'text':
- case 'textarea':
- $(this).val('');
- break;
- case 'checkbox':
- case 'radio':
- this.checked = false;
- }
- });
- }
- });
- });
- });
Add Comment
Please, Sign In to add comment