Javascript not receiving data from form onsubmit for Ajax call

Tom Wall

Every time I enter in the 3 parameters, and click submit, I am alerted with "name=&startDate=&endDate=". It's not updating $('#request') after I click submit. Does anyone see where I may be going wrong?

Here is my HTML:

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="match.js"></script>
<script src="Chart.js"></script>
</head>

<body>

<form id="request" onsubmit="match.js">
    <label>Name <input type="text" name="name" id="name" ></label>
    <label>Start Date <input type="date" name="startDate" id="startDate" ></label>
    <label>End Date <input type="date" name="endDate" id="endDate"  ></label>
    <input type="submit" value="Submit">
</form>

</body>
</html>

And my Javascript:

$(function(){
  $(function(e){
    $.ajax({
      url: 'match_api.php',
      type: 'post',
      data: $('#request').serialize(),
      dataType: 'json',
      success: function(data) {
          alert($('#request').serialize());
     });
     e.preventDefault();
  });
});
epascarello

I am not sure where you learned this

onsubmit="match.js"

Does nothing at all other than cause a JavaScript error. It does not magically bind the JavaScript file to the function.

If you want to attach to the submit event, you need to do

$(function(){
    $("#request").on("submit", function(e){
        $.ajax({
          url: 'match_api.php',
          type: 'post',
          data: $('#request').serialize(),
          dataType: 'json',
          success: function(data) {
              alert($('#request').serialize());
          }
         });
         e.preventDefault();
    });
});

and the HTML would just be

<form id="request">

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Controller ActionResult methods parameter is not receiving form data from an ajax call

From Dev

Getting selected data in Form from Select2 ajax call

From Dev

Accessing data sent in json form from server in ajax call

From Dev

View is not receiving POST data from form

From Dev

onsubmit still submits form even on return false from ajax verification

From Dev

Laravel 5.1: Ajax data is not receiving from server

From Dev

Sending data from jquery ajax and receiving data from php

From Dev

How to get value of a HTML tag receiving from ajax call

From Dev

How to Transfer data from JavaScript to Model using AJAX call

From Dev

return data coming through an ajax call from a javascript function

From Dev

how to export data from database into excel using ajax call + javascript

From Dev

How to display data from AJAX call to div using Jquery or Javascript?

From Dev

Extracting data from HTML form with inputs with JavaScript or AJAX and then passing it on to PHP

From Dev

onSubmit form - Ajax request to validate the form

From Dev

Securing data in javascript ajax call

From Dev

Securing data in javascript ajax call

From Dev

Receiving data in Ajax for a Div

From Dev

Where to add onsubmit to a form in Javascript

From Dev

Form Action & Javascript Onsubmit issue

From Dev

post json + form data in single ajax call

From Dev

Sending form data to DataTables ajax call

From Dev

jquery ajax call -submitting some form data

From Dev

Receiving php data via ajax as an array instead of responseText in my javascript

From Dev

Call Android App from Other App and receiving Data with getLaunchIntentForPackage

From Dev

Change Ajax from onclick to onsubmit

From Dev

PHP not receiving data from HTML5 form

From Dev

Receiving data in php server from form using $.post

From Dev

receiving data from ajax to php doesn't work

From Dev

Form submit and Ajax at the same time using onsubmit?

Related Related

  1. 1

    Controller ActionResult methods parameter is not receiving form data from an ajax call

  2. 2

    Getting selected data in Form from Select2 ajax call

  3. 3

    Accessing data sent in json form from server in ajax call

  4. 4

    View is not receiving POST data from form

  5. 5

    onsubmit still submits form even on return false from ajax verification

  6. 6

    Laravel 5.1: Ajax data is not receiving from server

  7. 7

    Sending data from jquery ajax and receiving data from php

  8. 8

    How to get value of a HTML tag receiving from ajax call

  9. 9

    How to Transfer data from JavaScript to Model using AJAX call

  10. 10

    return data coming through an ajax call from a javascript function

  11. 11

    how to export data from database into excel using ajax call + javascript

  12. 12

    How to display data from AJAX call to div using Jquery or Javascript?

  13. 13

    Extracting data from HTML form with inputs with JavaScript or AJAX and then passing it on to PHP

  14. 14

    onSubmit form - Ajax request to validate the form

  15. 15

    Securing data in javascript ajax call

  16. 16

    Securing data in javascript ajax call

  17. 17

    Receiving data in Ajax for a Div

  18. 18

    Where to add onsubmit to a form in Javascript

  19. 19

    Form Action & Javascript Onsubmit issue

  20. 20

    post json + form data in single ajax call

  21. 21

    Sending form data to DataTables ajax call

  22. 22

    jquery ajax call -submitting some form data

  23. 23

    Receiving php data via ajax as an array instead of responseText in my javascript

  24. 24

    Call Android App from Other App and receiving Data with getLaunchIntentForPackage

  25. 25

    Change Ajax from onclick to onsubmit

  26. 26

    PHP not receiving data from HTML5 form

  27. 27

    Receiving data in php server from form using $.post

  28. 28

    receiving data from ajax to php doesn't work

  29. 29

    Form submit and Ajax at the same time using onsubmit?

HotTag

Archive