Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
*brainstorming* What arguments do you pass through to the function, do they contain all the data you need and in the correct format? Do you pass through mutable objects? Are you attempting to return something from the function (wrong) or do you use callbacks (right)? Have you accidentally declared some variable(s) as global or local?
These are some ideas, not sure if this helps. -
CptFox16197yJavascript scopes are bitches, all of them. Try using arrow functions instead of the function keyword? Look them up if you don't know them yet, the difference is how they handle scope, which is probably linked to your issue
-
Tip: "return output;" When is this called and where is the return value returned?
-
@TerriToniAX output is called when the request is completed and returned to the innerhtml of "out" element. I even tried writing it differently I still can't find what's wrong. Lol and yes a tip will help
-
@BurningSatan Nope. It's not returned there. It's returned upon the event onreadystatechanged being fired.
document.getElementById('out').InnerHTML is set to the return value of *ajReq*. And what does ajReq return? Precisely. Nothing. -
@simus Sorry, he's been stuck with it for days so I just felt I had to give him a firmer push in the right direction :)
-
simus2467yme to, but it's the best way to learn.
@BurningSatan javascript is a bitch, never trust it, console.log is your best friend to understand how this mf work -
@TerriToniAX @simus
I rewrote the code and now it works. Thanks. Btw I still can't figure out what was wrong with the previous code. -
@BurningSatan In your new code, you don't seem to set the contents of HTML element "out" anywhere. I take it that "it works" in this case means that you get expected output using the console.log method. It works because you output the responsetext inside the anonymous callback function instead of returning it to the event that triggered the callback. (The caller event does nothing with the return value). Don't worry, asynchronous code can be cumberlicated at first, but once you master it it's quite straightforward actually. As @simus said, think asynchronous. I'd like to add to that, think of each event as a thread, think reentrant.
Trying to put together all the code of my ajax request into a function so I do not repeat myself. The code works perfectly outside but not in the function. Well fuck JavaScript. I've been stuck here for two days.
undefined