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

  • SEARCH
  • Home
  • 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 8831517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:19:37+00:00 2026-06-14T08:19:37+00:00

I have the following script which is not working for some reason: success: function(

  • 0

I have the following script which is not working for some reason:

success: function( widget_data ) 
{ 

    if( widget_data.d[0] ) {

        var j = 0;

        for ( j = 0; j <= widget_data.d.length - 1; j++ ) {

            $.getScript( "js/" + widget_data.d[j].script, function() {

                // this line is complaining about .widget_id
                alert(widget_data.d[j].widget_id);
            });

            // but this line works fine...
            alert(widget_data.d[j].widget_id);

        }

    }

}

I get an error on the following line, with one withing .getScript:

alert(widget_data.d[j].widget_id);

The error message is:

Cannot read property 'widget_id' of undefined

But the strange thing is, the following alerts work fine and return the correct values:

alert(widget_data.d[j].widget_id);

What am I doing wrong?

  • 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-14T08:19:39+00:00Added an answer on June 14, 2026 at 8:19 am

    The getScript call runs asynchronously capturing the variable j not it’s value at the time it is invoked. This means that j likely has the value that terminated the loop at the time the call returns. You should call the getScript within a function so you can capture the value of j rather than it’s reference. Actually, it’s probably better to actually capture the “widget” object itself, as you can see in the code sample.

    success: function( widget_data ) 
    { 
    
        if( widget_data.d[0] ) {
    
            var j = 0;
    
            for ( j = 0; j <= widget_data.d.length - 1; j++ ) {
    
                getWidgetScript( widget_data.d[j] );
    
                alert(widget_data.d[j].script);
    
                // but this line works fine...
                alert(widget_data.d[j].widget_id);
                alert(widget_data.d[j].title);
    
            }
    
        }
    
    }
    
    function getWidgetScript(widget) {
        $.getScript( "js/" + widget.script, function() {
            $( ".widget_header_" + widget.widget_id ).text( widget.title );
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason the script below is not working. This is the code I
I have the following script which is not working as I am expecting it
I have the following python script which takes some inputs and puts them in
I have the following script, which is working for the most part Link to
I have the following function in a PHP script, which returns and API call:
All, I have some script tags that are not working in Wordpress. If I
I have the following script which has stopped working due the error in the
I have the following script on this page which handles the fading in and
I have the following script which first shows only the first para of the
I have the following script which appears multiple times on my page. I have

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.