Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $("form#pessoasCadastrar" ).submit(function( event ) {
- event.preventDefault();
- data = $("form#pessoasCadastrar" ).serialize(),
- url = '/pessoas/salvar',
- var posting = $.post( url, { formData: data } );
- posting.done(function( data ) {
- if(data.fail) {
- $.each(data.errors, function( index, value ) {
- var errorDiv = '#'+index+'_error';
- $(errorDiv).addClass('required');
- $(errorDiv).empty().append(value);
- });
- $('#successMessage').empty();
- }
- if(data.success) {
- $('.register').fadeOut(); //hiding Reg form
- var successContent = '<div class="message"><h3>Registration Completed Successfully</h3><h4>Please Login With the Following Details</h4><div class="userDetails"><p><span>Email:</span>'+data.email+'</p><p><span>Password:********</span></p></div></div>';
- $('#successMessage').html(successContent);
- } //success
- }); //done
- });
- public function rules(){ ... }
- public function messages(){ .... }
- public function response(array $errors)
- {
- if ($this->ajax() || $this->wantsJson())
- {
- return response()->json($errors, 422);
- }
- $dados = array('fail' => true, 'errors' => $errors);
- return response()->json(array('fail' => true,'errors' => $errors));
- }
- public function salvar(PessoaRequest $request){
- $p = new Pessoa();
- [....]
- return Response()->json(array('success' => true,$request->all()));
- {"fail":true,"errors":{"nome":["O campo nome u00e9 obrigatu00f3rio!"]}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement