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.