7
My function calling my web service
var email = document.getElementById("email").value
var senha = document.getElementById("senha").value
$.ajax({
url: "http://localhost:8080/Servidor/rest/service/loginCustmerUser/"+ email + ","+ senha,
dataType: "json",
type: "GET",
async: false,
success: function (data) {
alert(data)
},
error: function(e){
alert("Erro: " + e);
},
});
My method in the webservice
@GET
@Produces("application/json")
@Path("/loginCustmerUser/{email},{senha}")
public String loginClientUser(@PathParam("email") String email,
@PathParam("senha") String senha) {
NotaFiscalBO bo = new NotaFiscalBO();
CustmerUser cUser = bo.loginCustmerUser(email);
try {
boolean validacao = validarCustmerUserLogin(senha,
cUser.getPassword());
if (!validacao) {
cUser = null;
}
} catch (Exception e) {
e.printStackTrace();
}
return new Gson().toJson(cUser);
}
Return of the method
{"id":3,"login":"test","password":"2482e34cc83b09ba9088b2af8bf11866"}
NAY use the GET method for this type of request!
– Rafael Telles
Try to return the object
cUser
normally without converting to JSON as seen in http://stackoverflow.com/questions/13594945/how-correctly-produce-json-by-restful-web-service– Rafael Telles
Where and how are you using this ajax call? Is it in form Submit? It can show the html code involved?
– Dherik
Rafael did it the way you said but not right, even as POST or returning my object goes straight to error. Dherik I’m calling on a button with onclick.
– roque
Rafael returned the object, in the browser it returns ok, but in ajax it goes straight to error
– roque