I got Error while passing RequestVerification Token ?
I got Error while passing RequestVerification Token ?
istudent_learning
Posts: 31Questions: 9Answers: 0
I am using Asp.net MVC 5 in back end. Whenever I pass request verification token I below error.
DataTables warning: table id=myTable - Ajax error. For more information about this error, please see http://datatables.net/tn/7
var oTable = $('#myTable').DataTable({
"ajax": {
"url": "/Home/Report/LoadReportData",
"type": "POST",
"datatype": "json",
"data": { '__RequestVerificationToken': $('[name=__RequestVerificationToken]').val() }
},
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
What are the results of following the troubleshooting steps in the URL provided by the error?
http://datatables.net/tn/7
Kevin
This is what developer tools logged
responsive.bootstrap4.min.js:5 Uncaught TypeError: Cannot read property 'display' of undefined
at responsive.bootstrap4.min.js:5
at responsive.bootstrap4.min.js:5
at responsive.bootstrap4.min.js:5
(anonymous) @ responsive.bootstrap4.min.js:5
(anonymous) @ responsive.bootstrap4.min.js:5
(anonymous) @ responsive.bootstrap4.min.js:5
The steps in the URL also have you looking at the Network Panel to see the response from the server. What is the server response?
Kevin
Status Code: 302 Found
Maybe you can post a link to your page for troubleshooting. If not then please provide debugger output. Post the URL generated.
https://datatables.net/manual/tech-notes/10#DataTables-debugger
Kevin
I can't post the link. this is for my work. I can provide you the js and css file I have included
302 is a redirect. My understanding, per the tech note above, Datatables expects a 2xx response. The 302 is being returned by your server. You will need to look at your server scrip to determine why its returning a 302 response.
Kevin
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
<script src="~/Scripts/DataTables/js/jquery.dataTables.min.js"></script>
<script src="~/Scripts/DataTables/js/dataTables.bootstrap4.min.js"></script>
<script src="~/Scripts/DataTables/Responsive/js/responsive.bootstrap4.min.js"></script>
my javascript code is
$(document).ready(function () {
If i do not include Token, It works fine. When i add the token i dont get data back.
Again you will need to look at your server script to determine why its returning a 302. Datatables has nothing to do with the error. AJAX is sending the parameter
__RequestVerificationToken
with the token value to the server. The server is, for some reason, responding with the 302.Kevin
var head = request.Headers.Get("__RequestVerificationToken");
I get null value.
As Kevin has mentioned, you'll need to look at your server-side script. I'm afraid we can't offer support for that. You are probably best asking on StackOverflow or similar if you don't know how to read information from the HTTP request.
I would point out that you are using
request.Headers.Get
but you aren't sending the verification token in the header. You are sending it in the request body.Allan
Thank you for reaching out. I realized that i was not creating token to pass. It is fixed now.