0

How Location Variable execute ?

var req = new XMLHttpRequest(); req.onload = reqListener; req.open('get','example.com/accountDetails',true); req.withCredentials = true; req.send(); function reqListener() { location='/log?key='+this.responseText; };

18th Mar 2021, 1:57 PM
Yaro Ka Yar
Yaro Ka Yar - avatar
2 Antworten
+ 2
Do you mean the "location" variable in this function? function reqListener() { location='/log?key='+this.responseText; }; If you do, it gets set when your request completes. That's because the reqListener() function is passed as the onload callback function when you set up your request: request.onload = reqListener
18th Mar 2021, 3:57 PM
CamelBeatsSnake
CamelBeatsSnake - avatar
+ 1
why did you have deleted your previous thread about same question? anyway, by 'Location Variable' did you mean second argument of req.open() call? if so, that's the url used to make the http request trough ajax... if this is an absolute complete url (starting with protocol -- usually 'http' or 'https'), it is used as is. if this is not, the url is build relatively to actual page url: at least prepennding the protocol, else using the domain name (if url start with '/') or at most computing the url relatively to page url...
18th Mar 2021, 2:57 PM
visph
visph - avatar