2015-03-03 17 views
0

我試圖從JS 調用後面方法的代碼,但它給了我這個錯誤(「NetworkError:401未經授權)調用後面方法的代碼從JavaScript

NetworkError: 401 Unauthorized 

這裏是後面方法的代碼

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

這裏是JS功能

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"); 
      } 
     }); 
    } 

這裏是響應

{ 
"Message": "An error occurred during the processing of the request", 
"StackTrace": "", 
"ExceptionType": "" 
} 
+0

可能重複: //stackoverflow.com/questions/23033614/asp-net-calling-webmethod-with-jquery-ajax-401-unauthorized) – 2015-03-03 08:29:55

回答

0

背後方法代碼需要是靜態的

簡單的解決方案:

[System.Web.Services.WebMethod] 
public static string ExtractToPDF(string FSID) 
{ 
    return FSID; 
} 
的[ASP.NET調用的WebMethod用jQuery AJAX 「401(未授權)」](HTTP
相關問題