"how to i send data from javascript to php and vice versa? " Code Answer

5

If you wish to submit this data via a form, you don't need to create the form with Javascript. Simply create an invisible form with HTML, populate the hidden field with Javascript, and automatically submit whenever you're ready.

  <form method="post" action="process.php">
    <input type="hidden" name="data" id="data" />
  </form>

  document.getElementById("data").value = "foo";

If you want to send this in an ajax-style fashion, I would suggest implementing jQuery, which makes this extremely easy. Note the previous case converted to a jQuery solution:

$.post("process.php", {data:"foo"}, function(results){
  // the output of the response is now handled via a variable call 'results'
  alert(results);
});
By ashinthankachan1999-e4cb3d10ea0c on November 16 2022

Answers related to “how to i send data from javascript to php and vice versa? ”

Only authorized users can answer the search term. Please sign in first, or register a free account.