<分区>
调用此异步 Web 方法时,出现 500 错误。还有其他方法可以异步调用 Web 方法吗?
堆栈跟踪:
Server Error in '/' Application.
Unknown web method SendMessage. 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 SendMessage. Parameter name: methodName
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentException: Unknown web method SendMessage. Parameter name: methodName]
System.Web.Handlers.ScriptModule.OnPostAcquireRequestState(Object sender, EventArgs eventArgs) +728343
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +92 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +165Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34248
ASPX 代码隐藏:
namespace Any.Contact
{
using System.Threading.Tasks;
using System.Web.Services;
public partial class ContactFormPage : PublishingLayoutPage
{
[WebMethod]
public static async Task<bool> SendMessage(string topic, string message)
{
return await SendEmail(topic, message);
}
}
}
JavaScript:
$.ajax({
type: "GET",
url: window.location.href + "/SendMessage",
data: {
"topic": jQuery('.ddl-topic').val(),
"message": jQuery('.tb-message').val()
},
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
success: function() {
$('.alert.alert-success').toggleClass('hidden', 'show');
},
error: function() {
$('.alert.alert-danger').toggleClass('hidden', 'show');
}
});