Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cliente
- id: NOT NULL AUTOINCREMENT PK,
- nome: VARCHAR(100),
- idade: INT,
- cpf: VARCHAR(11)
- class Medidor extends Model
- {
- protected $table = 'medidor';
- public $timestamps = false;
- }
- public function salvar(Request $request){
- try{
- $cliente = new Cliente( );
- $cliente->nome = $request->input('nome');
- $cliente->idade = $request->input('idade');
- $teste = $cliente->save();
- $obj = array(
- 'retorno' => true,
- 'msg' => 'Operação realizada com sucesso!'
- );
- return response()->json($obj, 200);
- }catch(Exception $exception){
- $obj = array(
- 'retorno' => false,
- 'log' => 'Error: '.$exception->getMessage(),
- 'msg' => 'Não foi possível salvar. '
- );
- return response()->json($obj, 400);
- }
- }
- $.ajax({
- url: acao,
- type: "post",
- dataType: "json",
- data: {
- id: 0,
- nome: 'Cliente',
- idade: 15
- }
- }).done( r => {
- console.log('r',r)
- if( r.retorno ){
- console.log('Deu certo')
- }
- }).fail((t)=>{
- console.log('Deu erro')
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement