ngrest javaScript client

0

How can I record data from a c ++ structure (being this server with ngrest) from java script.

the structure that I have in ngrest to register through json is this:

==========================encabezado=======================
#ifndef SERVIDORFASE1_H
#define SERVIDORFASE1_H

#include < ngrest/common/Service.h >

struct EstudianteSerializa
{
     long carnet;
     long dpi;
     std::string nombre;
     std::string apellidos;
     std::string fechaNacimiento;
     std::string direccion;
     int numcredito;
     std::string imagen;
     std::string password;

};

// *location: servidorfase1
class ServidorFase1: public ngrest::Service
{
public:
    // *method: POST
     // */location: /insertarEstudiante/{estudiante}
   std::string insertarEstudiante(EstudianteSerializa estudiante);

};


#endif // SERVIDORFASE1_H


=====================clase implementada=================
std::string ServidorFase1::insertarEstudiante(EstudianteSerializa estudiante){
  std::string respuesta="estudiante agregado exitoso";
  Estudiante _estudiante;
  _estudiante.carnet=estudiante.carnet;
  _estudiante.dpi=estudiante.dpi;
  _estudiante.nombre=estudiante.nombre;
  _estudiante.apellidos=estudiante.apellidos;
  _estudiante.fechaNacimiento=estudiante.fechaNacimiento;
  _estudiante.direccion=estudiante.direccion;
  _estudiante.numcredito=estudiante.numcredito;
  _estudiante.imagen=estudiante.imagen;
  _estudiante.password=estudiante.password;
  arbolito->insertar(_estudiante);
  return respuesta;
}
===========================consumiendo desde javascript===================
$('#formularioUsuario').on("submit",function(){
    $('#formUsuario').modal('hide');
    $.ajax({
    method: "POST",
        url:'http://localhost:9098/servidorfase1/insertarEstudiante', **//direccion para relizar la peticion**
        data: $("#formularioUsuario").serialize(), //**como serializo esta parte donde obtengo datos del from y mandarlo como un json en mi servidor para registrar los datos en ngrest donde tengo las estructuras correspondientes**
        datatype:'json',
        error:function(){alert ("error") },
        success:function(datos){
                 console.log(datos);                                         
//imprimirDatos(datos);
        }
    });
      event.preventDefault();
});
    
asked by Yovany Samines 01.09.2018 в 03:30
source

0 answers