Function inside jquery returns undefined

Posted by steamboy on Stack Overflow See other posts from Stack Overflow or by steamboy
Published on 2010-03-24T02:21:21Z Indexed on 2010/03/24 2:23 UTC
Read the original article Hit count: 378

Filed under:
|
|
|

Hello Guys,

The function I called inside jquery returns undefined. I checked the function and it returns correct data when I firebugged it.

function addToPlaylist(component_type,add_to_pl_value,pl_list_no) 
    {
        add_to_pl_value_split = add_to_pl_value.split(":");

        $.ajax({
            type: "POST",
            url: "ds/index.php/playlist/check_folder",
            data: "component_type="+component_type+"&value="+add_to_pl_value_split[1],
            success: function(msg)
            {
                if(msg == 'not_folder')
                {
                    if(component_type == 'video')
                    {
                        rendered_item = render_list_item_video(add_to_pl_value_split[0],add_to_pl_value_split[1],pl_list_no)
                    }

                    else if(component_type == 'image')
                    {
                        rendered_item = render_list_item_image(add_to_pl_value_split[0],add_to_pl_value_split[1],pl_list_no)
                    }
                }
                else
                {
                    //List files from folder
                    folder_name = add_to_pl_value_split[1].replace(' ','-');

                    var x = msg; // json 
                    eval('var file='+x); 

                    var rendered_item;

                    for ( var i in file )
                    {
                        //console.log(file[i]);
                        if(component_type == 'video')
                        {
                            rendered_item = render_list_item_video(folder_name+'-'+i,file[i],pl_list_no) + rendered_item;
                        }

                        if(component_type == 'image')
                        {
                            rendered_item = render_list_item_image(folder_name+'-'+i,file[i],pl_list_no) + rendered_item;
                        }
                    }
                }

                $("#files").html(filebrowser_list); //Reload Playlist

                console.log(rendered_item);

                return rendered_item;
            },
            error: function()
            {
                alert("An error occured while updating. Try again in a while");
            }
         })         
    }

$('document').ready(function()
{
    addToPlaylist($('#component_type').val(),ui_item,0); //This one returns undefined
});

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript