<html>
<head>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(function()
{
$('button[type="submit"]').on('click',function(e)
{
e.preventDefault();
var submit_value = $(this).val();
jQuery.post
(
);
});
});
</script>
</head>
<body>
<form method="post" action="php page" id="the-form">
Name <input type="text" name="name" > <br/>
Number <input type="text" name="number" > <br/>
<button type="submit" name="Submit">submit</button>
</form>
</body>
</html>
What should I write to jQuery.post to send the data from the form to a php page, I tried some posibilities but when I clicked submit the php page responded "No value". I don't have to change anything at the php page just in this script.
Your references are off
$('button[type="submit"]').on('click',function(e)
This will observe your submit button, not the form. So when you get to this
$(this).val();
It's looking at your submit button (which has no value), not your form data. Instead, you should grab the form and observe the submit
event and then serialize the data
$("#the-form").on( "submit", function(e) {
e.preventDefault();
var data = $(this).serialize();
jQuery.post('your/url.php', data, function(resp) {
//Do something with the response here
});
});