Error consuming JSON. RESTful Angular app.js

1

I have the following project, quite simple, that consumes the following JSON object obtained from a local web service.

{"nombre":"Miguel","id":1,"profesion":"Desarrollador"}

My app.js is like this:

$(document).ready(function(){
    $.ajax({
        url: "http://localhost:8080/RESTfulApp/rest/lista/verificar"
    }).then(function(data){
        $('verificar-nombre').append(data.nombre);
        $('verificar-id').append(data.id);
        $('verificar-profesion').append(data.profesion);
    });
});

And the index like this:

<!DOCTYPE html>
<html ng-app>
<head>
<meta charset="ISO-8859-1">
<title>Prueba Angular</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script src="src/main/webapp/js/app.js"></script>
</head>
<body>
    <div>
        <p class="verificar-nombre">Nombre</p>
        <p class="verificar-id">ID</p>
        <p class="verificar-profesion">Profesion</p>
    </div>
</body>
</html>

When executing the project, the chrome console returns error 404 with the following information:

The structure of my project is as follows and so you can see this all correctly, any idea why the index does not find my app.js?

    
asked by Miguel Angel 03.01.2018 в 14:06
source

1 answer

0

in this part: "url:" link ", in case" verify "is your json you can not add the extension ".json", besides the selectors are missing the point, since you are looking for them based on their classes:

$('.verificar-nombre').append(data.nombre);

And I recommend that you use a js framework that you have well defined, JQuery or Angular.

    
answered by 03.01.2018 в 16:36