Jump to content

Include the Output of a PHP File


LOLcayter

Recommended Posts

I have an HTML form that I've used to send data to a PHP script. I know this must be elementary, but how can I now get the output of said script and immediately display it on my webpage? It would be like

What is the answer to the universe?Form 1: DataForm 2: Data"Submit"The answer is: _____
to (when you click submit)
What is the answer to the universe?Form 1: DataForm 2: Data"SubmitThe answer is: 42!!!!
But this must be without refreshing the page or anything, just having it show up. I've tried every type of include I can think of and it doesn't do anything... Any help would be greatly appreciated.
Link to comment
Share on other sites

The only way you can do this without refreshing is JavaScript. But this means that the answer would be inside the source of the page, but also, that users with JavaScript disabled won't be able to view the answers.There are some workarounds for both issues.You can use xmlhttprequest() a.k.a. AJAX to fetch the answer from the server, but the form itself will have to be composed in another form.You can use JavaScript to disable the submit button for the PHP file and/or use alternative button for the AJAX fetch. When JS is disabled, the submit button won't be hidden and/or the other won't be available. This will force the user to refresh the page, but would at least enable him/her to view the answers.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...