function foobar(){
$.ajaxSetup ({cache: false});
var response = $.get("http://mysite.com/return.php")
document.write(response);
}
I’m trying to save the response from this as a variable. How can I do that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
$.get is an asynchronous AJAX call – your document.write line is going to execute long before the server even sends you a response.
If you want to access the return value, you’ll need to do it in a callback, like so: