-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubmit_laravel.js
64 lines (57 loc) · 1.75 KB
/
submit_laravel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
$.fn.formSubmit = function() {
$(this).on('submit', function(){
$('#show_error').html('');
var that = $(this),
url = that.attr('action'),
type = that.attr('method'),
data = {};
that.find('[name]').each(function(index, value){
var that = $(this),
name = that.attr('name'),
value = that.val();
that.parent().removeClass('has-error');
data[name] = value;
});
$.ajax({
url: url,
type: type,
data: data,
success: function(response) {
//console.log(response.name);
var error_div = $('#show_error');
error_div.fadeIn(2000);
error_div.css({"padding": "10px", "position": "fixed", "right": "0", "bottom": "60px"});
if (response.status === true) {
that.find('[name]').each(function(index, value){
var that = $(this);
error_div.removeClass('alert-danger');
error_div.addClass('alert-success');
error_div.html(response.message);
that.val('');
error_div.fadeOut(7000);
});
return false;
}
if (response !== undefined) {
error_div.removeClass('alert-success');
error_div.addClass('alert-danger');
$.each(response, function(key, value){
if (value !== '') {
var show_error = that.find('[name='+ key +']');
show_error.parent().addClass('has-error');
show_error.val('');
value = '<p>'+ value +'</p>';
error_div.append(value);
}
});
error_div.children().css({"padding": "5px", "margin": "0px"});
error_div.fadeOut(7000);
}
},
error: function (errors) {
//console.log(errors);
},
});
return false;
});
};