U
U
unlik2018-03-26 03:03:22
PHP
unlik, 2018-03-26 03:03:22

How to send data from the calculator on the site?

In general, the site has a calculator in the form of a table.
We enter the data, we see the final cost.
The cost using a script is written to the p tag with the article_cost class,
how can this cost be sent to the mail?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
Talyan, 2018-03-26
@flapflapjack

In browser:

<p class="article_cost" id="test">213</p>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


<script>
alert($(".article_cost").html());

$.post(
  "/ajaxtest.php",
  {
   calculated: $(".article_cost").html()
  },
  onAjaxSuccess
);
</script>

On server:
$f=fopen("log.txt","a");
fwrite($f,$_POST['calculated']);

X
xmoonlight, 2018-03-26
@xmoonlight

Send to the server (POST request directly or via AJAX), and from the server - already to the mail.
It won't work without a server.

S
Stalker_RED, 2018-03-26
@Stalker_RED

FormData + XMLHttpRequest (ajax), or fetch, or something similar.
Examples: https://developer.mozilla.org/en-US/docs/Web/API/F...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question