I posted a topic yesterday where a fella made a comment: How to use $_GET path with file_exists and keep it safe? stating that I’d get “undefined” returned due to JSON being asynchronous. He was right and I’ve been trying to wrap my head around why, but I feel completely out of my depth. I wonder if someone could explain just what’s happening so I can figure out how to use Deferreds to solve this or if there’s another solution.
Any help appreciated, cheers!
You code is
The problem here is that the inner function is a callback and the
returninside will be executed after the Ajax request. At this time the outer functionfileExistshas already finished. It only started the request and does not wait for it to end.To fix this you can make a callback
Use it like this