Javascript:有冲突还是我做错了?

时间:2015-03-31 01:42:29

标签: javascript jquery

这是我的页面: http://sitesdemo.mghospedagem.com/ivam-entregas/3/33209.html

我正在使用此代码通过ajax获取数据:

    $(document).ready(function() { //Quando documento estiver pronto

    $('#btnEnviar').click(function() { /* Quando clicar em #btn */
            function();

            /* Coletando dados */
            var nome = $('#nome').val();
            var email = $('#email').val();
            /*
            var distance = $("#distance").text();
            var duration = $("#duration").text();
            var costs = $("#costs").text(); */
            var msg = $('#txtDetalhes').val();
            var end1 = $('#1').val();
            var end2 = $('#txtEnderecoChegada').val();


            if (nome.length <= 3) {
                alert('Informe o seu nome');
                return false;
            }
            if (email.length <= 3) {
                alert('Informe o seu email');
                return false;
            }
            if (end1.length <= 3) {
                alert('Informe o endereço de partida');
                return false;
            }
            if (end2.length <= 5) {
                alert('Informe o endereço de chegada');
                return false;
            }
            if (msg.length <= 5) {
                alert('Informe os detalhes');
                return false;
            }

            /* construindo url */

            /* var urlData = "&nome=" + nome + "&email=" + email +  "&end2=" + end2 + "&distance=" + distance + "&duration=" + duration + "&costs=" + costs + "&msg=" + msg + "&end1=" + end1; */

            var urlData = {
                "nome": nome,
                "email": email,
                "distance": distance,
                "duration": duration,
                "costs": costs,
                "msg": msg,
                "end1": end1,
                "end2": end2
            };

            // Ajax 


            $.ajax({
                type: "POST",
                url: "sendmailivam.php", // endereço do phpmailer
                async: true,
                data: urlData, // informa Url
                success: function(data) { // sucesso 
                    $('#retornoHTML').html(data);
                },
                beforeSend: function() { // antes de enviar 
                    $('.loading').fadeIn('fast');
                },
                complete: function() { // completo 
                    $('.loading').fadeOut('fast');
                }
            });


        );


        function(evt);

        // extract all the values

        var data = []; $('#resultado span').each(function(index, item) {
            var id = $(item).attr('id');
            data[id] = $(item).text();
        });
        // do we have all the values?
        console.log(data);
        // POST the values to backend.php (adjust the URL).
        $.ajax({
            type: "POST",
            url: "sendmailivam.php",
            data: data,
            success: function(response) {
                console.log(response);
            }
        });




    });

});

或者至少它应该获取数据。每当我点击发送按钮时,我都不会采取任何行动。这让我想知道什么是错的。

0 个答案:

没有答案