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 8104505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:52:08+00:00 2026-06-05T23:52:08+00:00

I am forced to use data from within the getJSON callback function outside of

  • 0

I am forced to use data from within the getJSON callback function outside of that function. Have a look:

$('#stars').raty({
        score: function() {
            var $value = 0;
            var $id = <?=$id?>;
            $.getJSON("getuserrating.php?id=" + $id, function(data) {
                $.each(data, function(key, val) {
                    $value = val;
                });
            });
            return $value;
        },
    });

This is what I tried but it failed, the $value is still set to 0, although inside the callback it’s definitely set to an actual value. I know why it fails, because the AJAX request is send asynchronously. The problem is, the correct way, doing everything inside the callback, is not possible. As you can see I need to retrieve the JSON object within the raty (a plugin) setup. I would just use $.ajax() and set that to synchronous but the documentation marks this as deprecated for 1.8. I’d rather not introduce a solution that I know will be deprecated in the future.

Is there any way at all to do this? Maybe I just don’t see the forest for the trees and there’s an easy solution right before me. Thanks in advance 🙂

  • 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-06-05T23:52:11+00:00Added an answer on June 5, 2026 at 11:52 pm

    Approach is backwards if you need to use ajax to get the score.

    Make the ajax call first, then pass the value to score within the ajax success

    $.getJSON("getuserrating.php?id=" + $id, function(data) {
              /* pseudo code here since I don't know the plugin and it's data requirments*/
             var score= data.score;
             $('#stars').raty({
                 score: score
             });      
    });
    

    EDIT: you can still pass the data into a score function this way also

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

Sidebar

Related Questions

I'm forced to use IE7 at work, and have just discovered that the MiniProfiler
Im populating a GridView from List so am forced to use TemplateField controls to
I have a command line executable that is run from a C# class library.
I use SQL Server Import and Export Wizard to transfer data from a remote
Currently, I fetch "list" data from my storage, "deque" it to work with that
I am forced to use phpquery::getJson for architecture reason and because the Curl php
I am forced to use VS2008 for the bulk of my projects at work,
I am starting to learn Python, but I'm forced to use a v2.6.2 interpreter.
I'm trying to write a stored procedure to copy a subset of data from
I have an ambitious requirement for an asp.net 2.0 web page that contains a

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.