How to hide echo output results in php

藏色散人
Release: 2023-03-08 17:26:02
Original
1904 people have browsed it

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);
Copy after login

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 ...    
...
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!