3

In my web app I am making a AJAX call to an asynchronous webmethod that does not return.

Default.aspx has async="True"

The asp script:

$.ajax({
    type: "POST",
    url: "Default.aspx/Process",
    data: params,
    contentType: "application/json; charset=utf-8",
    success: function (data) {
         $("#AjaxDiv").text(data.d);
    },
    error: function(textStatus, errorThrown) {
          $("#AjaxDiv").text(textStatus.responseText);
          alert.text(textStatus.responseText);
    }  
});

On the server, the code is:

[WebMethod]
public static async Task<string> Process(int id)
{
    var data = await DataInterface.Call(id);
    return data.ToString();
}

However, DataInterface.Call() never returns, although via the debugger, I can see that Call() does complete. What settings or attributes might I be missing? whether it be in the app/web configs or page settings.

7
  • Ajax call itself is asynchronous, do you also need another async method on the server side? I would just use a regular method instead. Commented Apr 12, 2020 at 20:35
  • The data interface getter is async and is not for me to change. I did try switching to a regular method and then using var data = DataInterface.call(id).GetAwaiter().GetResult(); with the same conclusion, a runaway orphan. Commented Apr 13, 2020 at 0:07
  • May be Ajax callback not possible, try postbackor use update panel callback. Commented Apr 13, 2020 at 0:18
  • I tried UpdatePanel and the same issue occurred. I suspect this is because UpdatePanel is interpreted AJAX. Similarly I then moved the ASP version of the button outside of the UpdatePanel and the data call ran fine. But the forced page refresh triggered by an ASP button erases page state, which is why I initially tried AJAX/HTML over the ASP controls. Commented Apr 13, 2020 at 6:13
  • Please double check your code against this example stackoverflow.com/a/21499435/10634638 Commented Apr 13, 2020 at 14:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.