0

I am trying to receive JSON data (listSize, MyList) from the server by Ajax on the client side. I don't know if this is applicable or not. the ajax part is not working in my code.

here it is

function createList(startIndex,endIndex){
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
            var myVar = '<%=request.getAttribute("objKey")%>';
            var myObj = eval('(' + myVar + ')');
            myObj.listSize = endIndex;
            for (i = startIndex; i < myObj.listSize; i++) {
                $('body').append('<div id="div'+ i +'" />');
                $('#div' + i).append(myObj.MyList[i]);
            }
        }
    };
    xhttp.open("GET", "ServerSide.java", true);
    xhttp.send();   
}
Roham Rafii
  • 2,929
  • 7
  • 35
  • 49

1 Answers1

0

When you say its not working are you getting an error or is the call not made to the server. Check the URL is correct or not (clientSide.jsp is this your server url?)

Regards, Nitin

Nitin Prabhu
  • 624
  • 6
  • 10
  • i am not getting the expected output .. i am not getting anything –  Mar 06 '16 at 12:28
  • i make updates please have a look –  Mar 06 '16 at 12:28
  • Nomally you will have URL such as xhttp.open("GET", "RetrievalServlet", true); and on the server side you will have servlet with mapping mentioned in the URL @WebServlet("/RetrievalServlet") public class DBRetrievalServlet extends HttpServlet { @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(jsondata) } – Nitin Prabhu Mar 06 '16 at 12:39