Here is your mistake: the member
success
is the function which just
does nothing in your code.
You simply assign some variable to some other variable in its body. Even if you have some code which can properly use the
result
object, there is nothing which would trigger this code.
It looks like you completely misunderstand asynchronous call. If it is asynchronous, at the moment of the statement
return result
is executed, you don't yet have
success
called. In other words,
result
is left uninitialized, or having the value you initialized it with
before your call to getMentions
. Isn't it obvious?
The solution is simple like hell: the call to
success
should make it all. You should not return anything, this is useless. The function
success
should complete all processing, including the side effect, which can be some DOM manipulation. It can call some other function which does it all depending on
data
. Let's say, you got valid JSON data string in
data
. Then parse JSON into some data structure, take that data and modify DOM based on it; for example, form some HTML and set it to
innerHTML
of some element, like div.
See also:
JSON — JavaScript | MDN[
^],
Ajax | jQuery API Documentation[
^].
—SA