Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function() {
- let financing_form = $('#financing_form');
- let alert_message = $('#financing_form .alert');
- // dapatkan alamat current url
- let url = window.location.href;
- // tukar pada bentuk array
- // cth: http://ppsis:8080/restructures/1/edit
- // [http, ,ppsis:8080, restructures, ...]
- let url_array = url.split('/');
- let input_types = $('.types');
- console.log(url_array[3]);
- // input value mengikut menu yg dipilih. Sekiranya ingin buat nama lain,
- // boleh gunakan if..else utk define value tersebut.
- // if (url_array[3] === 'financings') {
- // input_types.val('FIN');
- input_types.val(url_array[3]);
- // }
- $('#financing_form .alert').hide();
- financing_form.submit(function(e) {
- e.preventDefault();
- let form_url = $(this).attr('action');
- let form_method = $(this).attr('method');
- alert_message.removeClass('alert-danger alert-success');
- alert_message.show();
- $.ajax({
- // url: '/financings',
- // type: 'POST',
- url: form_url,
- type: form_method,
- dataType: 'json',
- data: financing_form.serialize()
- })
- .done(function(data) {
- alert_message.addClass('alert-success');
- $('.alert.alert-success').html('Success add data');
- $('.modal').animate({scrollTop: '11px'}, 500);
- console.log(data);
- })
- .fail(function(data) {
- alert_message.addClass('alert-danger');
- let errors = data.responseJSON.errors;
- let error_msg = "";
- console.log("error: ");
- console.log(errors);
- for(let error in errors){
- console.log(errors[error]);
- error_msg += '<li>' + errors[error] + '</li>';
- }
- $('.alert.alert-danger').html("<ul>" + error_msg + "</ul>");
- $('.modal').animate({scrollTop: '11px'}, 500);
- })
- .always(function() {
- console.log("complete");
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement