Last active
January 4, 2016 14:57
-
-
Save fearrr/941b6b30bab9b7f475fa to your computer and use it in GitHub Desktop.
Нихрена не работает
This file contains 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
$.ajaxSetup({ | |
headers: { | |
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') | |
} | |
}); | |
var loginform = $('#login-form'); | |
var erroralert = $('#validation-errors'); | |
loginform.submit(function(e){ | |
e.preventDefault(); | |
var email = $('#login-email').val(); | |
var password = $('#login-password').val(); | |
var remember = $('#login-remember').val(); | |
$.ajax({ | |
type: 'POST', | |
url: 'auth/login', | |
cache: false, | |
dataType: 'json', | |
beforeSend: function(){ | |
erroralert.hide().empty(); | |
alert(email + password + remember); | |
}, | |
data: { | |
email: email, | |
password: password, | |
remember: remember, | |
}, | |
success: function(data){ | |
if(data.success == false) | |
{ | |
var arr = data.errors; | |
$.each(arr, function(index, value) | |
{ | |
if (value.length != 0) | |
{ | |
$("#validation-errors").append('<div class="alert alert-danger"><strong>'+ value +'</strong><div>'); | |
} | |
}); | |
$("#validation-errors").show(); | |
} else { | |
location.reload(); | |
} | |
}, | |
error: function(data){ | |
var errors = $.parseJSON(data.responseText); | |
console.log(errors); | |
$.each(errors, function(index, value) { | |
erroralert.append('<div class="alert alert-danger"><strong>'+ value +'</strong><div>'); | |
}); | |
erroralert.show(); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment