Results 1 to 1 of 1

Thread: Async webmethod from frontend

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2014
    Melbourne, Australia

    Async webmethod from frontend

        Public Shared Async Function TestAjaxCall(ByVal url As String) As Threading.Tasks.Task(Of Boolean)
            Using client = New HttpClient()
                client.BaseAddress = New Uri(url)
                client.DefaultRequestHeaders.Accept.Add(New MediaTypeWithQualityHeaderValue("application/json"))
                Dim response As HttpResponseMessage = Await client.GetAsync("/api/v1/accounts")
                If response.IsSuccessStatusCode Then
                    Return True
                    Return False
                End If
            End Using
        End Function
    Got the above code that I need to call from front end that is plugged into the project. Needs to be done like this for CORS reasons that we cannot change.

    I am calling the code like so
        fetch('http://localhost:27578/organisation/manage/manage.aspx/TestAjaxCall', {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
          body: JSON.stringify({ url: '' }),
          .then(response => response.json())
          .then(parsedJson => console.log(parsedJson.d))
          .catch(err => setCheckConnection(false));
      }, []);
    It worked when my TestAjaxCall was not async and returning a simple boolean and not passing a body to it. But now it just in the network tab sits as pending. I put a breakput on the response if statement but it never gets hit just keeps pending. Any ideas would be great! I'll update with other trials that i attempt. Not sure if TestAjaxCall is mean't to be POST maybe?
    Last edited by sharpCode#; Sep 18th, 2020 at 06:01 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width