I am using MVC and using jQuery AJAX I called a action method the data I received from the action method is correct and when I use $("#id").val() it is showing the data correctly in the form of json but it is throwing error in console

Uncaught SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at GetExistingSubList (310:2611:34)
    at HTMLDocument.<anonymous> (310:2392:17)
    at fire (jquery-1.12.4.js:3232:31)
    at Object.fireWith [as resolveWith] (jquery-1.12.4.js:3362:7)
    at Function.ready (jquery-1.12.4.js:3582:13)
    at HTMLDocument.completed (jquery-1.12.4.js:3617:10) 

Due to this error some of the JS functions aren't working

This is my controller code

[HttpPost]
        public ActionResult Getsubscriptiondata()
        {
            var subdata = db.ExistingSubscriptionList.Where(substatus => substatus.OSCP_SubStatusId == "1").ToList();

            return Content(JsonConvert.SerializeObject(subdata));
        }

This is my JS function with AJAX call

function getExistingSubValue() {
        $.ajax({
            type: "POST",

            url: "/UserManagement/Getsubscriptiondata",
            contentType: false,
            data: {
            },
            cache: false,
            success: function (data) {
                
                $("#hdnExistingSubs").val(data);
                
            }
        });
    }

This is the JS code where I am using the data by parsing it

if (ServiceId != '' && CloudId == '1' && IdentityTenantId != '') {
                var flag = 0;
                var data = $('#hdnExistingSubs').val();

                var items = JSON.parse(data);

                var table = $('#tblExistingSubs').DataTable();
                table.rows().remove().draw();

                var result = [];
                for (var item, i = 0; item = items[i++];) {
                    result.push(item);
                }

Image of the Error enter image description here

I have tried parsing the data after AJAX success call even it is throwing same error

0

There are 0 best solutions below