trying to load jsonobject to ajax , console showing unexpected identifier near ajax , any clue
trying to load jsonobject to ajax , console showing unexpected identifier near ajax , any clue
yadav46k
Posts: 6Questions: 2Answers: 0
hi all ,
when i load the page only header name is getting displayed . tested my json format it is valid json format as per JSONLint . Any suggestions what might be the issue .
<script
src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet"
href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css"></link>
<script>
$(document).ready(function() {
$('#example').DataTable( {
"ajax": "#{jsonConversionAction.showDetails()}",
dataType: "json",
"columns": [
{ "data": "name" }
]
} );
} );
</script>
<table id="example" class="display" style="width: 100%">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
</table>
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi @yadav46k ,
It looks like you only have a single column of data, is that correct? Also, I don't understand the Ajax settings, I suspect it should be:
If that doesn't help, could you provide a link to your page or create a fiddle showing the problem, please.
Cheers,
Colin
hi @colin ,
for testing purpose i had taken only one column right now . #{jsonConversionAction.showDetails()} is a java method which will return my JSONObject . is this the problem ?
had made the changes which you had mentioned still it is the same error . One thing i observed is if it is '#{jsonConversionAction.showDetails()}', it is showing the layout of datatable and if it is "#{jsonConversionAction.showDetails()}" page is blank and in console it is showing Uncaught SyntaxError: Unexpected token : and only name is getting displayed , Am i missing any thing here .
please correct me ..
No, if you look at my example, the
ajax
is an object, with the other options inside. Your one should look like:it is showing as** Failed to load resource: the server responded with a status of 404 (Not Found)** it is not identifying my java method here @colin
Should i go with REST API creation ?
I don't understand what this is supposed to be -
'#{jsonConversionAction.showDetails()}'
. I'm new to JS so it might be valid, but it looks curious to me. If it's supposed to be a function, look at this example here - that may get you going,Cheers,
Colin
hi @colin ,
tried the way you had specified . The output is coming as attachment , any idea how to parse it . or is there any issue with my code .
Hi,
Could you add:
in between lines 7 and 8 in the above code please? Then copy and paste the output on the console into here so we can take a look.
Thanks,
Allan
Hi @allen ,