I would like to know what is wrong with my function, because by assigning obj = data
, it saves object object
, the date value being a JSON returned by WEBSERVICE.
Date value:
[{"descricao":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. In tristique \nligula sed nibh finibus, id placerat elit mollis. Proin dictum sed felis vitae vulputate. Nunc vitae velit feugiat, porttitor \nfelis quis, pharetra risus. Integer id dolor sapien. Aenean ultricies, risus at lacinia blandit, leo mi tincidunt risus, \nat gravida nisi nisl ut dui. Donec vitae consectetur urna. Phasellus at augue vel nisl semper aliquet eu vel ante. Ut venenatis \nlacus id velit aliquet, ac congue neque mollis. Quisque at elit mollis arcu condimentum imperdiet.","idEvento":3,"inicio":"05/10","palestrante":"Profº José Marinho","qtdVagas":40,"termino":"09/10","titulo":"Palestra de Jogos"}]
JavaScript Function:
$(document).ready(function(){
$(".btnSubmit").click(function(evt) {
evt.preventDefault();
$.ajax({
type: "GET",
url: "http://localhost:8080/SemanaEngenharia/webresources/services.evento",
data: "", /* redundante */
dataType: "text",
success: function(data) {
alert(data);
obj = JSON.parse(data); /* nao funciona*/
//$("#p").html(obj.titulo);
alert(obj);
}
}); // fim ajax
});
});
When doing obj.titulo
(one of the JSON fields), the return is "undefined".