Hello. How to make a request to the database via Aјax? I have two divs. On the left is a list of all entries from the database (but in a truncated form, 100 characters) And when I click, I want the entire entry to appear in the right div.

My jsp file

<div> <div> <div class="noteContextWindow" > <c:forEach items="${listNotes}" var="note"> <div class="notesList"> <a href="/notedata/${note.id}">${note.noteTitle}</a> <br/> <a class="contextInList">${note.noteContent}</a> </div> </c:forEach> </div> </div> <div class="noteContext"> <a> Some text </a> </div> </div> 

text from the base should appear where it says "Some text"

    1 answer 1

    Hello,

    As an option, where sendAjax is an HTML id in HTML:

      $(document).ready(function() { $("#sendAjax").click(function(){ send(); }); }); send: function(){ $.ajax({ url:"/test", type:"POST", dataType: 'json', accepts: "application/json", contentType: 'application/json', mimeType: 'application/json', data : {"key":"value"}, success : function(data){ console.log(data); }, error : function(data){ console.log("error: "+data); } }); } 
    • And it is possible in more detail how I can use js in jsp. Thank. - Maksims
    • <script type = "text / javascript"> <% @ include file = "/ WEB-INF / js / handle.js"%> </ script> - Bohdan Korinnyi
    • I am sorry, I did not put it correctly. I meant how can I process the click itself in jsp to start the js code? - Maksims
    • JSP - <input type="button" id="sendAjax" value="Show"> JS - $(document).ready(function() { $("#sendAjax").click(function(){ send(); }); }); - Bohdan Korinnyi
    • Is it possible to somehow handle clicking on an entry in the list of entries? - Maksims