jQuery Plugin with $.getJSON Returning undefined?

Posted by Oscar Godson on Stack Overflow See other posts from Stack Overflow or by Oscar Godson
Published on 2010-06-15T17:16:22Z Indexed on 2010/06/15 17:22 UTC
Read the original article Hit count: 243

Inside of a jQuery plugin I made I have:

$.getJSON(base_url,{
    agenda_id:defaults.id,
    action:defaults.action+defaults.type,
    output:defaults.output
},function(json){
    return json;
});

And in a separate JS file (yes, it comes after the plugin):

json = $('#agenda-live-preview').agenda({action:'get',type:'agenda',output:'json'});
alert(json[0].agenda_id);

If i do the above $.getJSON and put an alert inside of the $.getJSON it works and returns "3", which is correct. If I do it like the json=$('#agenda-live-preview').agenda(...)... it returns undefined.

My JSON is valid, and the json[0].agenda_id is correct also, I know it's in a callback, so how do I get the stuff inside of a callback in a function return?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery