3
I would like to know the following how do I give Return in a function created by me, in a situation below. Because it always returns Undefined the object, but when I give an alert it returns the normal object.
  function jjson(url){
            var result;
            $.getJSON( url, function(data) {
                alert(data)
                result = data;
            });
            return result;
        }
ATT
Thank you... ATT
– abcd
So it is impossible to use the data outside of it, put in a variable or give a return to be used?
– user45722
@Exact Winefile. Any JSON code that has to be called/used within the callback of the
getJSON. You can for example call a function, passing JSON as argument. So you run code with this new data coming from JSON.– Sergio
@Sergio Since it is not possible to do this, I do so
<script>var theme = <?= json_encode(new \Skreth\System\Theme()); ?>;</script>can be considered gambiarra?– user45722
@Viníciusfile works fine if the data is static. If you need to fetch fresh data without reloading the page then
getJSONis the best. Failed to implement withgetJSON?– Sergio
@Sergio are static data, about the theme’s default colors, type:
Secondary: "gray600"Featured: "cyan". Then I would like to access them more or less like this:theme.Secondary. That way I can, but I don’t know if it’s 100% right– user45722
@Viniciuuslima ok, then putting in a
varsounds good to me– Sergio