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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:28:40+00:00 2026-05-27T14:28:40+00:00

EDIT To make it easier to read I’ve rewritten my explanation here. In short,

  • 0

EDIT

To make it easier to read I’ve rewritten my explanation here.

In short, a function in remote .js file requires a global variable. A previous function in remote .js file brings that var into the page with the jQuery .load(), but the function that requires the variable is not finding it after the .load() has brought it into the page. Below functions are in chronological order.

The remote .js file is loaded into the main page before the .load() page is.

Below is the code that I have:

Function Loads Remote Page Into Main Page (in remote .js file)

$(".activity_choice").live('click',function(e) {
    var selection = $(this).attr('id');
    var address = my_url + "pg/course/activity_form?style=" + selection + "&activity=" + activity;
    $("#stage_choice_holder").load(address,function(){
    });
});

The Global Var Coming In With Loaded Page

var controls_setup = $.parseJSON('<?php echo json_encode($setup);?>');

The Final Function That Should Save Things Using This Variable (in remote .js file)

$("#save_controls").live('click',function(e) {
    datastr = "&activity=" + activity;
    $.each(controls_setup, function (i,elem) {
        datastr += "&"+elem+"=" + $("#"+elem).attr('value');
    });
    $.ajax({
        type: "POST",
        url: my_url + "action/course/saveactivitycontrols",
        data: datastr,
        dataType: "json",
        success: function(msg){
        }
    }); 
});

The global variable controls_setup is not being recognized (I think), because when the $(".activity_choice").live('click',function(e) { is clicked the main page is already rendered with the remote .js file in it. This function brings the global variable in, but I’m guessing the DOM isn’t picking it up. So the final function that requires this var can’t find it.

Hope this is clearer.
Any help much appreciated. I am a somewhat novice with jQuery.

  • 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-27T14:28:41+00:00Added an answer on May 27, 2026 at 2:28 pm

    It’s very hard to tell exactly what’s going on in that code, because there’s lots of code quoted which is unrelated to the problem, and (conversely) it’s quoted in somewhat disconnected bits. (You’ve fixed that, nice one.)

    But if I understand you correctly, this call from your first code block:

    $("#stage_choice_holder").load(...);
    

    …is loading HTML with embedded script elements from a PHP page, and in a script element on that page you have:

    var controls_setup = $.parseJSON('<?php echo json_encode($setup);?>');
    

    First off, you don’t want that parseJSON call, simply this:

    var controls_setup = <?php echo json_encode($setup);?>;
    

    json_encode will return valid JSON, which conveniently (and intentionally) is a subset of JavaScript object literal notation, so the end result there is that controls_setup will receive a reference to an object. This may actually be the problem, because throwing single quotes around the output of json_encode may well result in a syntax error (if there are any single quotes in the material output by json_encode, or line breaks).

    Then in code later, you’re trying to access controls_setup and not seeing it.

    Although not best practice, that should work because of the way jQuery ensures things get loaded. Here’s a very simple example of it (live copy):

    jQuery(function($) {
    
      display("Before: " + typeof foo);
      $("#target").load("http://jsbin.com/uwigok", function() {
        display("After: " + typeof foo);
      });
    
      function display(msg) {
        $("<p>").html(msg).appendTo(document.body);
      }
    });
    

    …which loads

    <div>Snippet</div>
    <script>
      var foo = "bar";
    </script>
    

    So it could be as simple as removing the parseJSON call per the above.

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

Sidebar

Related Questions

I have a crystal report file I need make a tiny edit in. It
Someone please edit my title to make this question more clear. It's easier to
Edit Make sure you don't juxtapose the request and response objects. things will be
EDIT: Just to make things clear, this problem was caused by a typo in
I want to make a edit profile form for my website. My idea is
I use Zend framework to build the forms, I want to make the edit
Edit For simplicity: I just want to make the most basic possible cursor that
I have to edit my question just to make it clear. What I need
Is there a way to make a click-to-edit control in silverlight? I've got some
i have to make a notepad where i write,edit,clear the text. this notepad need

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.