Home > Article > Backend Development > How to hide echo output results in php
php solution to hide echo output results: first open the corresponding PHP file; then check the ajax request; finally hide the echo through "if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])..." Just output the result.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
Specific questions:
Sending data from php script to javascript function
echo json_encode($rows);
When the page loads, I am running the php script and then the output is displayed on the page which is actually what I don't want to display .I tried hiding the echo with ob_end_clean(), but that seemed to break everything.
Solution:
You can check the ajax request like this
/* AJAX check */ if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { /* your ajax here code will go here */ header('Content-type: application/json'); echo json_encode($rows); exit(); } //non ajax code ... ...
echo will only run if it is an AJAX call
[Recommended learning: "PHP Video Tutorial"]
The above is the detailed content of How to hide echo output results in php. For more information, please follow other related articles on the PHP Chinese website!