0

I am having a problem getting data from jquery into a php script. I am trying to load a php script (i.e. send an email) with a variable (email address) from jquery event without leaving the original page and going to a confirmation page. Please help!

Here is my jquery code:

<script>
  $("#test").click(function() { 
    var id = 1;
    $("#target").load("javascript_test2.php", id);

  });
</script>
<div id="target">hmmm did it work?</div>
</body>

This is the php I would like to receive and process the code:

<div id="S1">
<?php 
$id = htmlspecialchars($_POST['id']);

for ($i=1; $i<=2; $i++) {
echo $id . 'Hello world ' . $i . '<br>'; 
}

require_once('lawyeralertemail.php');

?>
</div>

Thanks!

1 Answer 1

2

You can use jQuery ajax to post data into your PHP. Here is a link: http://api.jquery.com/jquery.post/

This will allow you to post data without reloading the page and give your user a better experience.

You can then use $_POST to capture the data inside your PHP.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! the site focuses on the jQuery side of the code, I can just use normal $id = htmlspecialchars($_POST['id']); on the php side? no other special code?
That is correct. Whatever you set your data to, you can capture through $_POST.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.