Invalid JSON Response : Jquery DataTables Plugin
Invalid JSON Response : Jquery DataTables Plugin
Below is my sample logiform:
<head>
<link type="text/css" rel="stylesheet"
href="/springmvclogin/resources/static/css/login.css">
</head>
<body>
<form:form id="login" bgcolor="#E4E8EC" onsubmit="submitLoginForm()" method="post" commandName="loginForm">
<h1>Log In</h1><br>
<fieldset id="inputs"><br>
<span class="input"><br>
<form:input cssClass="username" path="userName" /> <br>
<form:password cssClass="password" path="password" /><br>
</span><br>
</fieldset><br>
<fieldset id="actions"><br>
<span class="input"><br>
<input type="submit" id="submit" value="Submit" /><br>
</span><br>
</fieldset><br>
</form:form><br>
<b>After Login --->Navigating to loginsuccess.jsp</b>
<H1>Below is the code for loginsuccess where I have written datatables logic</H1>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Spring pagination using data tables</title>
<br>
<br>
<link type="text/css" rel="stylesheet" href="/springmvclogin/resources/static/css/jquery.dataTables.css"><br>
<script type="text/javascript" src="<spring:url value="/resources/static/js/jquery-1.10.2.js" />"></script><br>
<script type="text/javascript" src="<spring:url value="/resources/static/js/jquery.dataTables.js" />"></script><br>
<br><br>
<script type="text/javascript"><br>
//Plug-in to fetch page data <br>
jQuery.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings )<br>
{<br>
alert("Plugin to fetch page data .....first javascript function **");<br>
return {<br>
"iStart": oSettings._iDisplayStart,<br>
"iEnd": oSettings.fnDisplayEnd(),<br>
"iLength": oSettings._iDisplayLength,<br>
"iTotal": oSettings.fnRecordsTotal(),<br>
"iFilteredTotal": oSettings.fnRecordsDisplay(),<br>
"iPage": oSettings._iDisplayLength === -1 ?<br>
0 : Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ),<br>
"iTotalPages": oSettings._iDisplayLength === -1 ?<br>
0 : Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength )<br>
};<br>
};<br>
$(document).ready(function() {<br>
$("#example").dataTable( {<br>
"bProcessing": true,<br>
"bServerSide": true,<br>
"sort": "position",<br>
//bStateSave variable you can use to save state on client cookies: set value "true" <br>
"bStateSave": false,<br>
//Default: Page display length<br>
"iDisplayLength": 10,<br>
//We will use below variable to track page number on server side(For more information visit: <br>http://legacy.datatables.net/usage/options#iDisplayStart)<br>
"iDisplayStart": 0,<br>
"fnDrawCallback": function () {<br>
alert("Current page number: "+this.fnPagingInfo().iPage);
}, <br>
"sAjaxSource": "${pageContext.servletContext.contextPath}/form/springPaginationDataTables.web",<br>
"aoColumns": [<br>
{ "mData": "patientId" },<br>
{ "mData": "patientName" },<br>
{ "mData": "sex" },<br>
{ "mData": "age" },<br>
{ "mData": "test" },<br>
{ "mData": "Description" },<br>
{ "mData": "noOfInstances" },<br>
{ "mData": "dateOfUpload" },<br>
{ "mData": "dateOfReport" },<br>
{ "mData": "center" },<br>
{ "mData": "noOfReports" },<br>
]<br>
} ); <br>
} );<br>
</script><br>
</head><br>
<body><br>
<form:form action="" method="GET"><br>
Spring MVC pagination using data tables
<br>
</form:form>
When I gave credentials,It is naviigating to loginsuccess and trying to redirect to
springPaginationDataTables.web.
While trying to use JQueryDataTables.js and Jquery.js ,,,
It is giving parse error and Invalid JSON Response warning
It is trying to parse loginform.jsp instead of data,
Can you please suggest me why it I am getting that Invalid JSON Response
It is working fine if we use CDN URL
Replies
Per the forum rules, we'd need a link to a test page showing the issue. It would be helpful if you use Markdown code highlighting for your code above as well.
If you are getting the invalid JSON warning, I would suggest you follow the instructions at the tech note that the warning message links to so see what the server is returning if it isn't JSON.
Allan