How to populate JSON valid data from server to jsp page

How to populate JSON valid data from server to jsp page

brijbrij Posts: 1Questions: 1Answers: 0

Hi - I am trying to populate data on jsp page from server. My jsp page is below:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Spring AJAX and JQuery</title>
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.0/css/jquery.dataTables.css">

function pagination(){ var name = 'Test'; var json = {"name" : name}; $.ajax({ url: "validateCaptchaThroughAJAX.web", type: 'POST', data: JSON.stringify(json), cache:false, beforeSend: function(xhr) { xhr.setRequestHeader("Accept", "application/json"); xhr.setRequestHeader("Content-Type", "application/json"); }, success:function(response){ //alert("Validation: "+response.validation+" Name: "+response.name+" Location: "+response.location); //$('#example tr:last').after('Donna SniderSupportNew York272011/01/25$112,000').dataTable(); $('#example').dataTable( { "processing": true, "serverSide": true, "ajax": response, "columns": [ { "data": "name" }, { "data": "position" }, { "data": "office" }, { "data": "extn" }, { "data": "start_date" }, { "data": "salary" } ] } ); }, error:function(jqXhr, textStatus, errorThrown){ alert(textStatus); } }); return true; }

</head>
<body>
<input type="button" value="Submit" onclick="pagination();">
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Extn.</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>

    <tfoot>
        <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Extn.</th>
            <th>Start date</th>
            <th>Salary</th>
        </tr>
    </tfoot>
</table>

</body>
</html>

JSON data return in reponse:

{
"data": [
{
"name": "Tiger Nixon",
"position": "System Architect",
"office": "Edinburgh",
"extn": "5421",
"start_date": "2011/04/25",
"salary": "$320,800"
}
]
}

I did check its valid JSON data but I always get error:
http://datatables.net/tn/7

Would you please help?

Thanks!

This discussion has been closed.