0
After days and days of research, I come to cry out to all of you to save my semester.
What I want is very simple: connect my javascript front-end with my java web service REST.
Just as a test, I created a GET method that returns all elements of my database (in xml, because JSON is not working) :
@GET
@Override
@Path("teste")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public List<Aluno> findAll() {
return super.findAll();
}
well. The problem is that I have no idea what to do in my javascript for: 1. communicate with this website and 2: capture the values returned from this xml
my javascript (that is not funncionando, this code got here on 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;
}
});
});
At first there are two errors: the correct one is
getElementsByClassName
("Elements" plural) and an index is needed, because thegetElementsByClassName
returns a nodelist, soon would bedocument.getElementByClassName(tituloFormulario)[0].value = data;
to change thevalue
of the first element of the class. The index[0]
is the first element.– Sam
And the variable
tituloFormulario
must be a class name.– Sam
sam, thanks for the reply, I made the changes you suggested (Document.getElementsByClassName(titleFormulario)[0].value = date;) and yes, titleFormulario is the name of a class of a randomized field that I used only to see the return of the web service. But when updating the page, it has no effect, I have no idea what could be wrong :/
– Weslley Fillipe
Missing a "c" in "Success".
– Sam
also fixed haha. The funny thing is that this code prevents my javascript from working, when I remove it, it works normally again
– Weslley Fillipe
You uploaded the jQuery library?
– Sam
Yes, everything is working normally. My real problem is that I don’t know how to communicate javascript with the webservice, so I can’t tell what’s wrong.
– Weslley Fillipe
Let’s go continue this discussion in chat.
– Sam