Home  >  Article  >  Backend Development  >  How to hide echo output results in php

How to hide echo output results in php

藏色散人
藏色散人Original
2021-03-12 11:00:481942browse

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.

How to hide echo output results in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn