Skip to content Skip to sidebar Skip to footer

Pass Js Variable To Php Using Ajax

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 va

Solution 1:

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.

Post a Comment for "Pass Js Variable To Php Using Ajax"