Jquery callback: access to javascript variables other than callback parameters?
-
From withing jquery callback method (such as success or error callback function, for example, in case of jquery ajax get request), how can I access variables other than callback function's parameters. In other words if I have a javascript variable - say, var error_message="blah ..." - how can I access it in an ajax callback - say complete: function(XMLHttpRequest, textStatus). In this particular case, I have access to only two variables - XMLHttpRequest and textStatus. How can I access other javascript variables - say a string variable defined elsewhere?
-
Answer:
I seem to have access to everything from the callback, even variables defined elsewhere. Make sure the variables you wanna access are within the scope of the callback, not within some other function.
r_b28 at Yahoo! Answers Visit the source
Other answers
What Khalid said is exactly right. Ensure that you're attempting to call a string or variable described within your function, and script. You cannot call or define variables from other functions / scripts, without writing a script to do just such that. XMLHttpRequest does this for you, but not in the scope or capacity that you desire.
Related Q & A:
- How to pass javascript jQuery variable value in php array?Best solution by Stack Overflow
- Why is this jquery callback for complete not executed?Best solution by Stack Overflow
- How to access a nested function from another nested function in javascript?Best solution by devarticles.com
- What is closure in Swift? Is it similar to callback in Javascript?Best solution by developer.apple.com
- how to define event to javascript/jquery?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.