Wednesday, 19 December 2018

MVC - JSON - Fix Error - 0x800a1391 - JavaScript runtime error: 'Json' is undefined


Watch this example on YouTube


Unhandled exception at line 199, column 13 in http://localhost:50023/Home/Index

0x800a1391 - JavaScript runtime error: 'Json' is undefined

to fix it replace
 function DeleteUser(e) {
            var row = $(e).closest('tr');
            var UserID = row.find($("[id*=hid]")).val();
            $.ajax({
                url: '@Url.Action("DeleteUser", "Home")',
                type: 'POST',
                data: Json.stringify({ UserID: UserID }),
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                success: function (response) {
                    if (response.ErrorMessage != null) {
                        alert(response.ErrorMessage);
                    }
                    else {
                        window.location.href = response.Url;
                    }
                },
                error: function (xhr, status, error) {
                    var el = document.createElement('html');
                    el.innerHTML = xhr.responseText;
                    alert(el.getElementByTagName('title')[0].innerText);
                }
            });
        }
with 

function DeleteUser(e) {
            var row = $(e).closest('tr');
            var UserID = row.find($("[id*=hid]")).val();
            $.ajax({
                url: '@Url.Action("DeleteUser", "Home")',
                type: 'POST',
                data: JSON.stringify({ UserID: UserID }),
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                success: function (response) {
                    if (response.ErrorMessage != null) {
                        alert(response.ErrorMessage);
                    }
                    else {
                        window.location.href = response.Url;
                    }
                },
                error: function (xhr, status, error) {
                    var el = document.createElement('html');
                    el.innerHTML = xhr.responseText;
                    alert(el.getElementByTagName('title')[0].innerText);
                }
            });
        }

No comments:

Post a Comment