Reputation: 23198
I know this has been asked on here but none of the answers I found answered my question.
I have a PHP/HTML file that the users view. When they click on a button, it creates a JS variable which I would like translated into a PHP variable. Using that variable, I would like to update the contents of a div box by calling a PHP function which populates the box with info from the server.
My questions: Can this be done with only 1 php file? Do I have to have the user reload the page after I refresh the content? What is the best way to do this?
Upvotes: 0
Views: 90
Reputation: 693
You can avoid the user reloading the page, but that would require AJAX. That raises the question - Does this need to work without JavaScript?
If you are happy for this to be dependant on JavaScript you could use an AJAX post, such as this using JQuery:
$.post( "example.php", { variableName: "example" })
.done(function( response ) {
$('.example-output').html( response );
});
example.php would be a different .php file, in example.php you would process the value of variableName
and produce the required markup, which would be displayed in the original page. If you need this to work without JavaScript then I would suggest reloading the page.
Upvotes: 3