JQUERY/AJAX GetData statement generating an error

Brown, Matt 126 Reputation points
2023-02-13T18:22:57.37+00:00

I did an inspect and a console.log. Both of which point to invalid code, but I'm not seeing where the issue is. I even mimicked similar code elsewhere which is working, and I'm still generating an error.

var data = $.ajax({
                type: "POST",
                contentType: "application/json; charset=unicode",
                url: '<%= ("aop.aspx/GetData") %>',
                data: "{'avzid': '" + avzid + "',  'authorfname': '" + authorfname + "','authorlname': '" + authorlname + "','generalsearch': '" + generalsearch + "'}",
                // select: "single",
                dataType: "json",
                async: false
            }).responseText.replace(/<\/?[^>]+>/gi, ''); //Remove markup
            
            data = data.replaceAll("\\", "");
            data = data.replaceAll("}}", "}");
            data = data.replaceAll("{\"data\":", "");
            data = data.replaceAll("{\"d\":", "");
            data = data.replaceAll("]}", "]");
            data = data.replaceAll("}}]\"}", "}]");
            data = data.replaceAll("}]\"}", "}]");
            

            var table = $('#dtable').DataTable();

            table.clear().draw();
            var i = 0;
            var j = [];
            // data = data.replace(/ 0+(?![\. }])/g, ' ');
            console.log('Data: ' + data);
            var dataSet = JSON.parse(data);

The error from the inspect points to the line below;

var dataSet = JSON.parse(data);
Uncaught SyntaxError: Unexpected token 'U', ..."
        Unknown we"... is not valid JSON
    at JSON.parse (<anonymous>)
    at HTMLButtonElement.<anonymous> (aop.aspx:458:32)
    at HTMLButtonElement.dispatch (jquery-3.5.1.js:5429:27)
    at elemData.handle (jquery-3.5.1.js:5233:28)

This is the error info I get from my console.log();

Server Error in '/' Application.

             Unknown web method GetData.Parameter name: methodName 

            

             Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

            

             Exception Details: System.ArgumentException: Unknown web method GetData.Parameter name: methodName
Microsoft 365 and Office Development Office JavaScript API
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.