cbassett03 Posted August 2, 2013 Share Posted August 2, 2013 Here is a segment of code that I'm using in a PHP script, which is called as part of an AJAX HTTP Request: <?php $result = $user_conn->execQuery($sql_query); while ($row = $result->fetch_array(MYSQLI_ASSOC)) { $resultText .= '<option value="'.$row['id'].'">'.$row['display_text'].'</option><br />'."\n"; } echo $resultText;?> NOTE: I created a MySQL class with custom functions, so execQuery() is a custom function I created that actually runs the query() command for SQL. Anyway, as you can see, to get the results back to the JavaSCript calling request function, I used ECHO. Is there an alternative so that if someone where to run just this PHP script directly, it wouldn't output any text (because right now it will)? (I asked this a few weeks ago but seem to have "lost" the post.) Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted August 2, 2013 Share Posted August 2, 2013 You can check for $_SERVER['HTTP_X_REQUESTED_WITH'] and optionally see if it == xmlhttprequest. Also, you might want to generate a token in PHP, stick it in the session, echo it to JS so it can use it as a var, send this token with each AJAX request and check for it in the PHP script. Quote Link to comment Share on other sites More sharing options...
cbassett03 Posted August 5, 2013 Author Share Posted August 5, 2013 So there isn't just a "return" keyword I can use to return the text value or variable? Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted August 5, 2013 Share Posted August 5, 2013 So there isn't just a "return" keyword I can use to return the text value or variable? Not back to an AJAX request no. 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.