JavaScript function that returns result of ajax call

Posted by ilkin on Stack Overflow See other posts from Stack Overflow or by ilkin
Published on 2010-04-21T10:59:24Z Indexed on 2010/04/21 11:03 UTC
Read the original article Hit count: 184

Filed under:
|

Hi guys. Help needed. Im writing a function that returns result of ajax call but i did not get any results, i guess it's a scope issue, but is there any way to do it? Here is my code:

function Favorites() {
    var links;
    $.ajax({
        type: "GET",
        url: "/Services/Favorite.svc/Favorites",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        cache: false,
        success: function(msg) {
            links = (typeof msg.d) == 'string' ? eval('(' + msg.d + ')') : msg.d;
        }
    });
    return links;
};

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript