clbassett03 Posted July 23, 2013 Share Posted July 23, 2013 (edited) Is there a way that I can prevent a PHP script that is part of an AJAX app from outputting text? Right now, at the end of the script, I have it ECHO the result back so that the calling script can retrieve the result from the PHP script. Is there an alternative? Can I use "return" or something, as opposed to "echo" to get the results back from the PHP script to the calling function (which in many cases the calling function is a Javascript function). The other thing is that the way I have my HTML form set up is that it doesn't submit or anything. The three lists I have changed automatically when one or more lists are changed, so there is no form submit happening. The AJAX scripts are simply triggered by events tied to the HTML elements, such as onChange and onBlur, etc. Right now, as I have it, if you browse to the page that the request object sends the request to for proessing, in some cases, the PHP script will display the results from the database based on the query embedded in the script, and I sort of don't want people to be able to just run the script and see the results directly,,,, Edited July 23, 2013 by clbassett03 Quote Link to comment https://forums.phpfreaks.com/topic/280414-preventing-ajax-php-scripts-from-outputting-text/ Share on other sites More sharing options...
requinix Posted July 23, 2013 Share Posted July 23, 2013 Is there a way that I can prevent a PHP script that is part of an AJAX app from outputting text? Right now, at the end of the script, I have it ECHO the result back so that the calling script can retrieve the result from the PHP script. Is there an alternative? Can I use "return" or something, as opposed to "echo" to get the results back from the PHP script to the calling function (which in many cases the calling function is a Javascript function).No. Outputting is how you return something through AJAX. Right now, as I have it, if you browse to the page that the request object sends the request to for proessing, in some cases, the PHP script will display the results from the database based on the query embedded in the scriptThen it sounds like you have a bug: your script is doing something it's not supposed to do. Figure out where the flaw in the logic is that's causing the script to output when not being triggered through an AJAX action. and I sort of don't want people to be able to just run the script and see the results directly,,,,You best get over those qualms soon because every user can see exactly what is sent and received over AJAX. And no, there's nothing you can do about it directly so make sure you don't need to send or receive anything you wouldn't want the user to know about. Quote Link to comment https://forums.phpfreaks.com/topic/280414-preventing-ajax-php-scripts-from-outputting-text/#findComment-1441755 Share on other sites More sharing options...
cbassett03 Posted July 25, 2013 Share Posted July 25, 2013 The information that is being sent isn't anything confidential. But what I've been doing is using an ECHO statement to return the result from the PHP processing script back to calling javascript function that invokes the script (as part of AJAX). Could i use "RETURN" instead of ECHO? I'm storing the result in a PHP variable, so couldn't I just say "return $variableName;" in my PHP script? Quote Link to comment https://forums.phpfreaks.com/topic/280414-preventing-ajax-php-scripts-from-outputting-text/#findComment-1442144 Share on other sites More sharing options...
requinix Posted July 25, 2013 Share Posted July 25, 2013 No. Outputting is how you return something through AJAX. If the use of the word "return" there is confusing then pretend I said "send something back". Quote Link to comment https://forums.phpfreaks.com/topic/280414-preventing-ajax-php-scripts-from-outputting-text/#findComment-1442155 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.