Skip to content

using fetch() #2176

Apr 14, 2023 · 3 comments · 2 replies
Discussion options

You must be logged in to vote

As the documentation of fetch() says, it resolves to a Response object, and Response.text() is a promise that resolves to the text content of the resource. You should do something like

def handle_content(s):
    print(s)
    
def fetched(ResJSobj):
    if ResJSobj.ok:
        ResJSobj.text().then(handle_content)
    else:
        print("it didn't work")

window.fetch('/aLocalPage').then(fetched)

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@BobSquarePants
Comment options

Comment options

You must be logged in to vote
1 reply
@BobSquarePants
Comment options

Answer selected by BobSquarePants
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants