SANJISH Posted July 5, 2020 Share Posted July 5, 2020 Hi, This is my first post in this forum and am a PHP beginner. I have written a script in php and need to use echo to see the values of variables etc. However I dont get the output on the screen while using echo . I am using Xampp server with Apache. The startup.html file code is <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script> <title>Test Page</title> <script> $.ajax( { url: "http://localhost:8081/test.php", type: 'POST', dataType: 'text', data: {latitude: '7.15588546', longitude: '81.5659984458'}, success: function (response) { alert(response); }, error: function (response) { alert(response); } }); </script> </head> <body> <p>hello</p> </body> </html> and the test.php code is <?php $lat = $_REQUEST['latitude']; $lon = $_REQUEST['longitude']; echo 'latitude- '.$lat . ', longitude- ' . $lon; ?> Please help regards Sanjish Quote Link to comment Share on other sites More sharing options...
requinix Posted July 5, 2020 Share Posted July 5, 2020 Then what do you get? Have you checked your browser's developer tools to see if there were any errors? Quote Link to comment Share on other sites More sharing options...
SANJISH Posted July 5, 2020 Author Share Posted July 5, 2020 I checked the developer tools and there were no errors only the echo is not displaying the values Quote Link to comment Share on other sites More sharing options...
requinix Posted July 5, 2020 Share Posted July 5, 2020 Are you sure your script is even running at all? Can you see the network request happen? Can you see the response? Quote Link to comment Share on other sites More sharing options...
SANJISH Posted July 5, 2020 Author Share Posted July 5, 2020 Yes the script is working because when i use error_log(variable name) in the script i can view the values in apaches error logs . Quote Link to comment Share on other sites More sharing options...
requinix Posted July 5, 2020 Share Posted July 5, 2020 Then there's something going on that I can't see. Most likely because I'm not sitting at your computer. Change the alert() to a console.log() and make sure you see that happening. Quote Link to comment Share on other sites More sharing options...
SANJISH Posted July 5, 2020 Author Share Posted July 5, 2020 Even console.log does not work. In fact any of the output functions like print_r , var_dump etc are not working. Quote Link to comment Share on other sites More sharing options...
Strider64 Posted July 5, 2020 Share Posted July 5, 2020 (edited) Make sure you have error reporting on - ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); If that isn't working then your local server isn't set up right. To test if you local server is working properly create a php info file. <?php // Show all information, defaults to INFO_ALL phpinfo(); Edited July 5, 2020 by Strider64 Quote Link to comment Share on other sites More sharing options...
SANJISH Posted July 5, 2020 Author Share Posted July 5, 2020 Whenever i use echo in the php file the ajax call returns a Parserror. If i remove echo then the ajax call is a success. Hope that helps . I am at my wits end really Quote Link to comment Share on other sites More sharing options...
SANJISH Posted July 5, 2020 Author Share Posted July 5, 2020 Whenever i use echo in the php file the ajax call returns a Parserror. If i remove echo then the ajax call is a success. Hope that helps . I am at my wits end really . I tried calling phpinfo() . But it shows nothing. What do i do to set the Xampp server right. ? Quote Link to comment Share on other sites More sharing options...
requinix Posted July 5, 2020 Share Posted July 5, 2020 I don't see any syntax errors in what you posted. Get yourself a decent IDE that supports syntax highlighting for PHP and it should be able to pinpoint where the issue is. Quote Link to comment Share on other sites More sharing options...
abhasgupta88 Posted July 16, 2020 Share Posted July 16, 2020 in the ajax "url" instead of http://localhost:8081/test.php just use test.php and try. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.