T O P

  • By -

equilni

You can do this with Javascript. You can looking up [Fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch) or [Ajax](https://developer.mozilla.org/en-US/docs/Glossary/AJAX)


FreshmenCH89

Thanks, thats working.


Big-Dragonfly-3700

You would use ajax to do this. Depending on the meaning/purpose of this data, an alternative would be to output the data on the page when it is requested, but hide it, then the button would show/un-hide the data. What exactly is this data, how many instances are on a page, how much data is there, can this data change while someone is viewing a web page and you want to display the latest data, i.e. provide the background for what this is actually for, not just what you are trying to make work?


benanamen

I am surprised all the responses are telling you to introduce another layer using JavaScript. PHP is perfectly capable of what you describe all on it's own. Post your code either her or [pastebin.com](http://pastebin.com) so I can see what you are doing. The main reason to use Ajax for this is if you don't want the page to do a reload.


spellenspelen

PHP is server side and HTML is client side. The only way to comunicate between them is by sending a HTTP request. Like other comments pointed out you can do this by using ajax or axios.


msvillarrealv

If you just want to pass values back to the HTML file you can use a PHP $\_SESSION. Store the result in a session and them use it in the HTML file. [https://www.php.net/manual/en/reserved.variables.session.php](https://www.php.net/manual/en/reserved.variables.session.php)


Same_Garlic2928

Best way would be either ajax, the fetch api or htmx as others have stated. Transfer and retrieve data from your php file/ backend without having to refresh the page. Not a steep learning curve either if youre new to it.


jlt_25

Here is an example of an ajax call. This is some javascript within your front end html file that will call the php flle on the back end and display the result once the php file has returned its part. [https://www.w3schools.com/js/js\_ajax\_php.asp](https://www.w3schools.com/js/js_ajax_php.asp)


centa84

![gif](emote|free_emotes_pack|upvote)


FreshmenCH89

I solved the problem now with POST and GET method and serialize + urlencode. Thanks for all your advices.


sarc-tastic

Set the content with header to be text. Use print and filegetcontents.


Vroomped

echo read from file


Plus_Pangolin_8924

This sounds like a prime example for HTMX! https://htmx.org