Ajax respones w/ PHP.
Moderator: General Moderators
Ajax respones w/ PHP.
Is it true that every time I echo something in my PHP file, that's requested by javascript, this would end up in the responesText of the XMLHttpRequest object?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
What all is considered output in this context?
Another thing is, could I start a session and set some session variables, with the requested php? For example, lets say my http request object requests a php page. That php page takes two values from the http request object (username and password). Then checks if the two values match specific values in the database and if so starts a session (i.e php session start function) and sets two session variables to the two values pass by the XMLHttpRequest object (username and password), therefor having the effect of logging in.
Another thing is, could I start a session and set some session variables, with the requested php? For example, lets say my http request object requests a php page. That php page takes two values from the http request object (username and password). Then checks if the two values match specific values in the database and if so starts a session (i.e php session start function) and sets two session variables to the two values pass by the XMLHttpRequest object (username and password), therefor having the effect of logging in.
anything that is sent to the client is output. If all you do is check request vars against a database, and then start a session, no output is sent. If your php is configured to use cookies, (which it is by default), your code will send headers to set the cookie on the user's browser, but there is no body in the response.
IE:
IE:
Code: Select all
<?php
session_start();
if (isset($_GET['username']))
{
logUserIn($_GET['username'], $_GET['password']);
}
// no output has been sent yet...
// so here's some output
echo 'output';
?>PHP files aren't really output since they are executed on the server. PHP can output xml, html, plain text, images etc. All ajax does is allow javascript to request output from php (or any other server-side technology) as opposed to your browser doing it via a form submission or you doing it by directly typing the uri into the url. (ie: http://www.yoursite.com/event.php?action=view&id=23)
I don't know what this means:
I don't know what this means:
all the variables, cookies and database interactions take place just not responded
actually after reading my own statement, to be more accurate, ajax doesn't even need to request output. It just needs to request. There is no rule stating that whatever you are requesting has to return output. Sometimes it's just deleting a record in the database or something, but generally even in this case, your server-side code would output a success message or something.