Results 1 to 2 of 2

Thread: Fetch within a Fetch Issue

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2022
    Posts
    115

    Fetch within a Fetch Issue

    Just starting out with Javascript and ran into a problem when trying to execute a fetch within a fetch. Looking for a way to execute code once the first fetch completes. Using ‘then’ doesn’t seem to work as the call below to AjaxFileLoadInit() invokes a second fetch and locks things up. If I call AjaxFileLoadInit() later on after the first fetch has finished by way of a link everything works.

    fetch(FileName)
    .then(res => res.text())
    .then(txt => Element.innerHTML = txt)
    .then(txt => AjaxFileLoadJavaFix(Element))
    .then(txt => AjaxFileLoadInit());

    Thanks.

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    12,130

    Re: Fetch within a Fetch Issue

    I apologize because my answer comes several months late, but looking at your code it should be executing asynchronously. Assuming that AjaxFileLoadJavaFix and AjaxFileLoadInit both return promises, your code should behave as expected.

    My guess is that the two methods don't actually return a promise, but could you provide us with those methods?
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

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