我在.aspx頁面的codebhind後面有一個web方法,但是當我嘗試訪問它時,並不會觸發webmethod只有頁面。返回狀態是200,頁面正在被調用,但該方法被忽略。不管我是否使用name.aspx/GetData或name.aspx/Anything,結果都是200,但是這個方法沒有被觸發。我用jQuery Ajax和Postman進行了測試。獲取和發佈嘗試。 有沒有什麼可以改變的web.config或任何其他的東西。.NET Web方法不僅僅是從javascript調用頁面
$.ajax({
url: '/adm/clientAccess.aspx/MyMethodInexistent',
data: {},
type: 'POST',
contentType: 'application/x-www-form-urlencoded',
dataType: 'html',
success: function (data) {
//I GET HERE even if the method doesn't exist, and if it exists, it doesn't return data.
alert(1);
},
error: function (response) {
alert(response.responseText);
}
}
);
如果您沒有發佈任何代碼,您會比我們更瞭解這個問題。我們怎麼可能幫你?請閱讀如何提出問題的指導原則:https://stackoverflow.com/help/mcve – JuanR
對不起,我現在添加了。 – AlvaroCryptogram
您正在使用哪個版本的.NET?它應該是'url:'/ adm/clientAccess.aspx/MyMethod','調用該方法。嘗試在方法中添加一個斷點,以查看是否能夠達到它。 – Niladri