How to send Jsp as a response to ajax call

I want to send a jsp page consisting of some div and table as part of ajax response from spring frame work, is there any way to send jsp as an answer to ajax call

+3
source share
2 answers

Submitting an AJAX JSP does not make sense, it is basically HTML code generated by the JSP that is sent to the browser via AJAX, as rightly points to thelost.

You do not need server-side coding for this. All you need to do is write client-side javascript to get your asynchronous HTML code. For this, I would recommend using some javascript framework, for example jQuery, otherwise it would make your life hell.

Assuming that the page you want to access, AJAX has a link http: // domain: port / mypage.htm . First you need to include jQuery in the JSP base (JSP in which the previous page should load AJAX):

<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.js"></script>

Then you need to call the jQuery ajax function:

$(document).ready(function(){
    $.ajax({
                        type:"GET",
                        url: "http://domain:port/mypage.htm",
                        success: function(data){
                            // Now you have your HTML in "data", do whatever you want with it here in this function         
                            alert(data);
                        }
                    });
});

Hope this helps!

+3
source

, . java- ajax jsp. responseText ajax.

jsp HTML, . javascript HTML, ,

element.innerHTML = resp.responseText 
//element is the parent you want to insert to 
//resp is the parameter supplied to your callback
0

Source: https://habr.com/ru/post/1755696/


All Articles