Advertisement
Guest User

Untitled

a guest
Apr 30th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. $("form#pessoasCadastrar" ).submit(function( event ) {
  2.  
  3. event.preventDefault();
  4.  
  5. data = $("form#pessoasCadastrar" ).serialize(),
  6. url = '/pessoas/salvar',
  7.  
  8. var posting = $.post( url, { formData: data } );
  9. posting.done(function( data ) {
  10. if(data.fail) {
  11. $.each(data.errors, function( index, value ) {
  12. var errorDiv = '#'+index+'_error';
  13. $(errorDiv).addClass('required');
  14. $(errorDiv).empty().append(value);
  15. });
  16. $('#successMessage').empty();
  17. }
  18. if(data.success) {
  19. $('.register').fadeOut(); //hiding Reg form
  20. 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>';
  21. $('#successMessage').html(successContent);
  22. } //success
  23. }); //done
  24. });
  25.  
  26. public function rules(){ ... }
  27. public function messages(){ .... }
  28.  
  29. public function response(array $errors)
  30. {
  31. if ($this->ajax() || $this->wantsJson())
  32. {
  33. return response()->json($errors, 422);
  34. }
  35. $dados = array('fail' => true, 'errors' => $errors);
  36. return response()->json(array('fail' => true,'errors' => $errors));
  37. }
  38.  
  39. public function salvar(PessoaRequest $request){
  40.  
  41. $p = new Pessoa();
  42. [....]
  43.  
  44. return Response()->json(array('success' => true,$request->all()));
  45.  
  46. {"fail":true,"errors":{"nome":["O campo nome u00e9 obrigatu00f3rio!"]}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement