This topic is locked

await fetch in js part of a button

7/12/2023 12:49:31 PM
PHPRunner General questions
G
Grdimitris author

I want to use await fetch call. In custom functions i set an async function gettoken(username,password) to return the login token.
but when i use in client after event the function gettoken is undentified.
How to make it work?
To call the url with fetch and get the response json to use it

Admin 7/12/2023

What kind of problem you are trying to solve by using await fetch as opposed to a regular jQuery's POST or GET?

G
Grdimitris author 7/13/2023

I didnt thought about it. The modern javascript make me thinking more complex solutions on the way to simplicity. Because after obtaining token the rest calls use that token to authenticate and response data, so i have to wait the first call and then to make the others. One solution is all the other calls to execute in success method of login call. Ok Ill try it

Admin 7/13/2023

Check this:
https://api.jquery.com/jquery.get/
You can execute your code once the response from the server arrives, use "success" callback function.