function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bpl3792bpl3792 

Confused as to why I'm losing scope of a variable using jquery/jsremoting

The code looks fine to me which is why I'm confused with the G_SResult variable losing scope. It's declared globally above the ready function but that isn't visible in the screenshot. In the screenshot you will see 4 highlighted alert expressions. The one with the red dot is where it returns undefined. The other alerts return the right value.

sfdcfoxsfdcfox

Nice image, by the way.

 

If I recall correctly, you're losing scope because G_SResult is scoped to "this.G_SResult", which is actually a member of the object created as a result of calling Visualforce.remoting.Manager.invokeAction, which won't be accessible inside Savedat. Instead, you need to define G_SResult either as a member of Savedat (var G_SResult;), or as a global variable as window.G_SResult.

 

Edit: Just re-read the post. You say it's defined globally, hmm? I suspect that JS is somehow not resolving to the object you think it should. Try being explicit with your command, such as window.G_SResult, or wherever this global variable may lie.