Jump to content

Recommended Posts

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 by clbassett03

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 script

Then 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.

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.