javascript - How to call a web method async in ASP.NET (SharePoint behind) -
this question has answer here:
calling async web method, 500 error. there other ways call web method async?
stacktrace:
server error in '/' application.
unknown web method sendmessage. parameter name: methodname
description: unhandled exception occurred during execution of current web request. please review stack trace more information error , originated in code.exception details: system.argumentexception: unknown web method sendmessage. parameter name: methodname
source error:
an unhandled exception generated during execution of current web request. information regarding origin , location of exception can identified using 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 codebehind:
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'); } });
you don't need use task, it'll called asynchronous js. can regular method returns bool. try:
namespace any.contact { using system.threading.tasks; using system.web.services; public partial class contactformpage : publishinglayoutpage { [webmethod] public static bool sendmessage(string topic, string message) { return sendemail(topic, message); } } }
Comments
Post a Comment