Sahrepoint 2019仅在ajax调用上抛出“此时无法启动异步操作”错误消息

时间:2019-04-23 08:59:28

标签: sharepoint

“此时无法启动异步操作。异步操作只能在异步处理程序或模块内或在页面生命周期中的某些事件期间启动。如果在执行页面时发生此异常,请确保标记了页面<%@ Page Async = \“ true \”%>。此异常也可能表示尝试调用\“ async void \”方法,ASP.NET请求处理通常不支持该方法,而是应返回异步方法一个任务,调用者应等待它。”

上面的异常在Ajax异步调用中引发了sharepoint 2019.但是在asp按钮中单击它可以正常工作

同一应用程序在SharePoint 2013和2016中都可以使用这两种情况

困惑为什么SharePoint 2019不支持异步Ajax调用?

Ajax调用

var text = "this is test";
$.ajax({
    type: "POST",
    async:true,
    contentType: "application/json; charset=utf-8",
    url: "ApplicationPage1.aspx/Test",
    data: "{'str':'" + text + "'}",
    dataType:"json",
    success: function (data) {

    },
    error: function (response) {
        alert(response);
    }
});

示例呼叫如下所示。

我已经将页面异步属性标记为true。

    [WebMethod]
    public static void Test(string str)
    {
        try
        {
            //Create object of the Binding
            Binding binding = new BasicHttpBinding();
            //Create endpointAddress of the Service
            EndpointAddress endpointAddress = new
            EndpointAddress("http://server/Service1.svc?wsdl");
            //Create Client of the Service
            client1 = new ServiceReference1.Service1Client(binding, endpointAddress);
            //Call Service method using ServiceClient
            client1.GetDataCompleted += client_GetDataCompleted;
            client1.GetDataAsync(2);
        }
        catch (Exception ex)
        {

            //TextBox1.Text = Convert.ToString(ex.InnerException);
        }
    }
    public static void client_GetDataCompleted(object sender, ServiceReference1.GetDataCompletedEventArgs e)
    {

    }

0 个答案:

没有答案