简体   繁体   中英

how to send all parameters through URL?

$(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();
            }
        });
    }

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'];
?>

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的工具和检查要求

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM