Form submit with AJAX passing form data to PHP without page refresh

0 votes

Can anyone tell me why this bit of code isn't working?

<html>
  <head>
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script>
      $(function () {
        $('form').bind('submit', function () {
          $.ajax({
            type: 'post',
            url: 'post.php',
            data: $('form').serialize(),
            success: function () {
              alert('form was submitted');
            }
          });
          return false;
        });
      });
    </script>
  </head>
  <body>
    <form>
      <input name="time" value="00:00:00.00"><br>
      <input name="date" value="0000-00-00"><br>
      <input name="submit" type="button" value="Submit">
    </form>
  </body>
</html>

Nothing happens when I press the submit button. I'm using $_POST['time'] and $_POST['date'] in the receiving PHP file to put the data in a MySQL query, but it's just not obtaining the data. Any recommendations? I assume that has to do with the submit button, but I'm not sure what that means.

Jul 29 in PHP by Kithuzzz
• 4,480 points
15 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In PHP

0 votes
1 answer

How to Validate Form Data With PHP?

Hey @kartik, The first thing we will do ...READ MORE

answered Feb 13, 2020 in PHP by Niroj
• 82,740 points
1,367 views
0 votes
1 answer

How to submit form without page reloading?

Hello @kartik, If you put an Iframe in ...READ MORE

answered Oct 6, 2020 in PHP by Niroj
• 82,740 points
629 views
0 votes
1 answer

How to check if the request is an AJAX request with PHP?

Hello @kartik, Try below code snippet if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) ...READ MORE

answered Oct 29, 2020 in PHP by Niroj
• 82,740 points
5,174 views
0 votes
0 answers

How to run a PHP function due to a button click (with button 'data' passed)?

I manage some sortiment items on a ...READ MORE

May 28 in PHP by Kichu
• 19,040 points
1,084 views
0 votes
0 answers

Getting PHP registration form to connect with MYSQL

I'm building a test site and my ...READ MORE

May 30 in PHP by Kichu
• 19,040 points
23 views
0 votes
0 answers

Passing variable from JS to PHP within the same page

I know that PHP is a server-side ...READ MORE

Jun 18 in PHP by narikkadan
• 11,280 points
19 views
0 votes
0 answers

jQuery: serialize() form and other parameters

Is it possible to send form elements (serialized with .serialize() method) ...READ MORE

Jun 29 in Web Development by gaurav
• 17,580 points
69 views
0 votes
1 answer

jQuery AJAX submit form

There is a simple input mentioned below ...READ MORE

answered Feb 8 in Java by Soham
• 8,740 points
255 views
0 votes
0 answers

Edit PHP query code depending on image map clicked area using AJAX

I am working on an image map ...READ MORE

Jun 3 in PHP by Kichu
• 19,040 points
23 views
0 votes
0 answers

Fetch data from database in php through AJAX,

The index.php  I created a connection with the ...READ MORE

Jun 16 in PHP by narikkadan
• 11,280 points
128 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP