Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

jrowan20jrowan20 Posts: 13Questions: 7Answers: 0

Hi All I am running into an invalid JSON error. Everythign was working perfect on Localhost, but now the site is on IIS the things broken. See below my jquery, network response and controller

namespace MaskFit.Controllers
    {

    [Route("/Mask")]
    [ApiController]
    public class MaskController : Controller
        {

        private readonly ApplicationDbContext _db;

        public MaskController(ApplicationDbContext db)
            {

            _db = db;

            }

        [HttpGet]

        public async Task<IActionResult> GetAll()
            {
            return Json(new { data = await _db.Mask.ToListAsync() });
            }

        [HttpDelete]
        public async Task<IActionResult> Delete(int id)
            {
            var maskFromDb = await _db.Mask.FirstOrDefaultAsync(u => u.Id == id);
            if (maskFromDb == null)
                {
                return Json(new { success = false, message = "Error Whilst Deleting" });
                }
            _db.Mask.Remove(maskFromDb);
            await _db.SaveChangesAsync();
            return Json(new { success = true, message = "Delete Successful" });
            }
        }
    }
var dataTable

$(document).ready(function () {
    loadDataTable();
});

function loadDataTable() {
    dataTable = $('#DT-load').DataTable({
        "ajax": {
            "url": "/mask",
            "type": "GET",
            "datatype": "json",


        },
        "columns": [
            { "data": "name", "width": "20%" },
            { "data": "author", "width": "20%" },
            { "data": "isbn", "width": "20%" },
            {

                "data": "id",
                "render": function (data) {
                    return `<div class="text-center">
                <a href="/MaskList/Edit?id=${data}" class='btn btn-success text-white' style='cursor:pointer; width:70px;'>
                Edit
                </a>
            &nbsp;
            <a  class='btn btn-danger text-white mx-auto' style='cursor:pointer; width:70px;'
                    onclick=Delete('/mask?id='+${data})>
            Delete
                </a>
                </div>`;
                }, "width": "40"
            }

        ],
        "language": {
            "emptyTable": "No Data found"
        },
        "width": "100%"

    });

}


//Sweet Alert Function

function Delete(url) {
    swal({
        title: "Are you sure?",
        text: "Once Delete you will not be able to recover",
        icon: "warning",
        buttons: true,
        dangerMode: true
    }).then((willDelete) => {
        if (willDelete) {
            $.ajax({
                type: "DELETE",
                url: url,
                success: function (data) {
                    if (data.success) {
                        toastr.success(data.message);
                        dataTable.ajax.reload();
                    }
                    else {
                        toastr.error(message);
                    }

                }
            });
        }
    })

}
Request URL: http://odgh-webapp-uat/masks?_=1604435258024
Request Method: GET
Status Code: 200 OK
Remote Address: 10.146.16.194:80
Referrer Policy: strict-origin-when-cross-origin
Content-Type: text/html; charset=utf-8
Date: Tue, 03 Nov 2020 20:27:36 GMT
Server: Microsoft-IIS/10.0
Transfer-Encoding: chunked
X-Powered-By: ASP.NET
Accept: application/json, text/javascript, */*; q=0.01
Accept-Encoding: gzip, deflate
Accept-Language: en-GB,en;q=0.9,en-US;q=0.8
Connection: keep-alive
Cookie: .AspNetCore.Antiforgery.6A-HjuGlSgs=CfDJ8FCglAuCLlJGqq2XVQMUUAUSieaecoWLJn7jobDBfMTOjwq6Zt8QUnrQJ7nS_GGmILzcdiyPJZG57YAQjb9R20dqsl9bbTc_mcmCwWDitum3mzfCW6Hz40GleUM8pqCY1ddr0isyCFOTohiI09hlJ4o
Host: odgh-webapp-uat
Referer: http://odgh-webapp-uat/masks/MaskList
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36 Edg/86.0.622.61
X-Requested-With: XMLHttpRequest

Is there anything obvious that I may be missing thank you

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    The best place to start would be to follow the diagnostic steps in the error message: http://datatables.net/tn/1 .

    Have you tried that? What did you find?

    Colin

  • hellodevinghellodeving Posts: 2Questions: 0Answers: 0

    DataTables warning: table id=user-list - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

  • hellodevinghellodeving Posts: 2Questions: 0Answers: 0

    how to resolve ?

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    As Colin suggested, have you followed the troubleshooting steps in the link provided?
    http://datatables.net/tn/1

    The response is coming from the server so you will need to troubleshoot what is happening at the server. The JSON response might indicate the error or you will need to review your server logs.

    Kevin

Sign In or Register to comment.