php_developer Posted November 8, 2012 Share Posted November 8, 2012 I want to store the "xmlhttp.responseText" into a global variable so that the response i am getting can be used in another function. xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { validvar=xmlhttp.responseText; alert(validvar); a=validvar; } Actually I want to show the response in a confirm box and if the user click ok only then go to next page or submit the form else in case of cancel the form shuld not be submitted. here a is the global variable. I am storing the xmlhttp.responseText into validvar and then in global variable a. But The global variable remains empty when I access it another function. OR if there is any other way to store the response so that i can use it in another function and in the confirm box.. Link to comment Share on other sites More sharing options...
JamesB Posted November 8, 2012 Share Posted November 8, 2012 xmlhttp.onreadystatechange=function(){if (xmlhttp.readyState==4 && xmlhttp.status==200){window.globalVariableName = xmlhttp.responseText;}}; function someOtherFunction() {confirm(window.globalVariableName);} Link to comment Share on other sites More sharing options...
justsomeguy Posted November 8, 2012 Share Posted November 8, 2012 Instead of using a global variable just pass it as a parameter to the next function. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now