how to connect javascript to webservice?

0

After days and days of research, I come to call on all of you to save my semester.

What I want is very simple: connect my javascript front-end with my web service REST in java.

Just as test, I created a GET method that returns all elements of my database (in xml, since JSON is not working):

@GET
@Override
@Path("teste")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public List<Aluno> findAll() {
    return super.findAll();
}

Well then. The problem is that I have no idea what to do in my javascript for: 1. communicate with this webservice and 2: Capture the returned values of this xml

My javascript (which is not working, this code I got here in the forum):

 $(document).ready(function(){
$.ajax({
    url: "http://192.168.1.100:8080/SemanaEngenharia/webresources/service.aluno/teste",
    sucess: function(data) {
        alert(data);
        document.getElementByClassName(tituloFormulario).value = data;
    }
});
});
    
asked by anonymous 16.11.2018 / 21:47

1 answer

0

I suggest you study how to return a JSON using JAava and then try to connect, take the alert date and put a console.log ()

console.log(data)

Another suggestion is to see if there is an error in chrome devtools. Possibly it may be CORS problem, you have to tell your server that this address can access the required resources. Let us know or put your project in github so we can understand the context.

    
19.11.2018 / 19:26