Home > Blockchain >  How to display a table with content from a database on a page? rest ajax spring boot application
How to display a table with content from a database on a page? rest ajax spring boot application

Time:11-19

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Cars Selling</title>

<script
    src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="listCarsSelling.js"></script>
</head>
<body>
    <h2>Cars Selling List</h2>

    <table id="table-content">
        <thead>
            <tr>
                <td>code</td>
                <td>manufacturer</td>
                <td>model</td>
                <td>color</td>
                <td>transmission</td>
                <td>body_type</td>
                <td>price</td>
            </tr>
        </thead>
    </table>

</body>
</html>

listCarsSelling.js

$(document).ready(function(){
    $.ajax(
        {
            type: "GET",
            url: "http://localhost:8080/ListCarsSelling",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            cache: false,
            success: function(data){
                
                for (var i=0; i<data.length; i  ) {
                     var row = $('<tr><td>'   data[i].code   '</td><td>'   data[i].manufacturer
                       '</td><td>'   data[i].model   '</td><td>'   data[i].color   '</td><td>'
                  data[i].transmission   '</td><td>'   data[i].body_type   '</td><td>' 
                  data[i].price   '</td></tr>');
                
                    $('#table-content').append(row);
                }
            },
            
            error: function(msg){
                allert(msg.responseText);
            }
        });
})

photo with error '404' for reference on the link 'http://localhost:8080/': enter image description here


I want the data from my database to be displayed immediately when I go to the main page. How can i do this? I also want to point out that I have no problems connecting to the database, since while developing rest i was able to extract json data. I just now need to display them somehow..

CodePudding user response:

Eh, the problem was painfully commonplace. Incorrect project structure. The application file was in another package, and it should be above all as shown here. omg

  • Related