Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 736999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:40:12+00:00 2026-05-14T07:40:12+00:00

Help needed. Im writing a function that returns result of ajax call but i

  • 0

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;
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T07:40:13+00:00Added an answer on May 14, 2026 at 7:40 am

    Your problem is that the HTTP request you’re making is asnychronous and your Favorites function returns before the Ajax request has come back. You will need to change your function so that it accepts a callback to be executed once the response has come back:

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

    Aside: convention is that only functions intended to be used as constructors should start with a capital letter, so your function would be better named as favorites.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Help! I am using jQuery to make an AJAX call to fill in a
A little help needed. I'm receiving an xml file similar to this: <?xml version=1.0
Help! I have an Axis web service that is being consumed by a C#
Help me ..my page index is not working in visual studio. my page load
HELP! I just setup a virtual host for two sites that have a lot
I'm writing a PHP script that retrieves steam user profile information (for a servers
I am writing code in C++ using Win32 API wherever needed. I wish to
I am writing a book viewer that dynamically loads content as the user scrolls
I am writing the code of an android activity that will display thumbnails of
I'm writing tests using WiPFlash for a WPF application that has been developed in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.