$.get("http://localhost/test.php", (function(data){
alert(data);
}))
The alert is empty. I’m new to this, and I can’t see what I’m doing wrong. Help?
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.
It does work with a
file://URL but nothttp://? I smell same origin policy.Are you opening the file with the jQuery in your browser via a
file://URL then trying to fetch viahttp://? Because your protocol and host have to match when you do Ajax.Make sure that you’re opening the file in your browser as
http://localhost/index.phpand notfile://localhost/index.php. Then you should be able to fetch that file viahttp://localhost/test.php.