0
$(document).ready(function () {
    $("#submitButton").click(function () {
            var name = $("#name").val();
            var age = $("#age").val();
            var gender = $('input:radio[name=gender]:checked').val();
            var contact_no = $("#contact_no").val();
            var city = $("#city").val();
            var concern = $("#concern").val();
            var email = $("#email").val();

            function ajaxcall(name, age, gender, contact_no, city, concern, email);
        }
    });

    function ajaxcall(name, age, gender, contact_no, city, concern, email) {
        jQuery.ajax({
            type: "POST",
            url: "http://adjetter.com/lp/lead-integration.html",
            data: {
                name: name,
                age: age,
                gender: gender,
                contact_no: contact_no,
                city: city,
                concern: concern,
                email: email
            },
            dataType: "html",
            success: function (data) {
                alert();
            }
        });
    }
Tushar
  • 85,780
  • 21
  • 159
  • 179
logan
  • 11
  • 2
    Remove `function` from the beginning of this `function ajaxcall(name, age, gender, contact_no, city, concern, email);`. You just want to call a function, not define one. – jfriend00 Nov 02 '15 at 03:35
  • Does the request have to be a POST? If not, just change it to `type: 'GET'` – Phil Nov 02 '15 at 04:09

2 Answers2

1

You should use this tested and working code instead:

$(document).ready(function(){
    $(document).on('submit', 'form', function(e) {
        e.preventDefault();

        var $form = $(this);

        ajaxcall($form.serialize());
    });

    function ajaxcall(data) {
        jQuery.ajax({
            type: "POST",
            url: "form.php?" + data,
            dataType: "html",
            success: function (data) {
                console.log(data);
            }
        });
    }
});

If the file you are sending the values is called form.php then you can access the data in form.php in this way:

<?php
    echo $_GET['name'] . ' ' . 
         $_GET['age'] . ' ' . 
         $_GET['gender'] . ' ' . 
         $_GET['contact_no'] . ' ' . 
         $_GET['city'] . ' ' . 
         $_GET['concern'] . ' ' . 
         $_GET['email'];
?>
Viktor Maksimov
  • 1,465
  • 1
  • 10
  • 11
0

I have modified your code.When you are using function ajaxcall(name, age, gender, contact_no, city, concern, email); , that is actually defining a new function instead of calling the existing function. Also you can take a look at better ways of passing paramters to a js function Pass a JavaScript function as parameter

$(document).ready(function (){
        $("#submitButton").click(function() {
                var name =$("#name").val();
                var age = $("#age").val();
                var gender = $('input:radio[name=gender]:checked').val();
                var contact_no = $("#contact_no").val();
                var city = $("#city").val();
                var concern = $("#concern").val();
                var email = $("#email").val();

               ajaxcall(name, age, gender, contact_no, city, concern, email)
            })

        });

    function ajaxcall(name, age, gender, contact_no, city, concern, email) {
         jQuery.ajax({
                type: "POST",
                url: "https://adjetter.com/lp/lead-integration.html",
                data: {
                    name: name,
                    age: age,
                    gender: gender,
                    contact_no: contact_no,
                    city: city,
                    concern: concern,
                    email: email
                },
                dataType: "html",
                success: function (data) {
                    alert();
                }
            });
        }

Have created a fiddle for convience. If you are using chrome, you can check the ajax request from developer's tool. Press F12 and look for the network tab, If the ajax execute you will see the ajax url getting called.Click on the the requested url and you will see an header option.Click on it to check the input parameters. jsfiddle Chrome Developer's tool & inspecting request

Community
  • 1
  • 1
brk
  • 48,835
  • 10
  • 56
  • 78