0

I am trying to call code behind method from JS but it gives me this error

NetworkError: 401 Unauthorized

Here is the code behind method

[System.Web.Services.WebMethod]
public string ExtractToPDF(string FSID)
{
   return FSID;
}

and here is the JS Function

 function extractFile(FSID) {
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "Update.aspx/ExtractToPDF",
            data: "{"+FSID+"}",
            dataType: "json",
            success: function(data) {
                alert(data)
            },
            error: function(result) {
                alert("Error");
            }
        });
    }

Here is the response

{
"Message": "An error occurred during the processing of the request",
"StackTrace": "",
"ExceptionType": ""
}
Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160
AddyProg
  • 2,960
  • 13
  • 59
  • 110
  • possible duplicate of [ASP.NET Calling WebMethod with jQuery AJAX "401 (Unauthorized)"](http://stackoverflow.com/questions/23033614/asp-net-calling-webmethod-with-jquery-ajax-401-unauthorized) – Sani Huttunen Mar 03 '15 at 08:29

1 Answers1

0

The code behind method needs to be static

Simple solution:

[System.Web.Services.WebMethod]
public static string ExtractToPDF(string FSID)
{
    return FSID;
}
Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160
AddyProg
  • 2,960
  • 13
  • 59
  • 110