我不想在提交后刷新我的表单,因为需要使用链接转到另一个页面

问题描述 投票:0回答:1

我不想在提交后刷新我的表单,因为需要使用inner.html链接转到另一个页面。请帮助。

enter code here
<script src="js/jquery.min.js"></script>
    <script>
        $(document).ready(function(){
            $('#form').on('submit', function(){
                var name = document.getElementById('name').value;
                var address = document.getElementById('address').value;
                 var email = document.getElementById('email').value;
                   var phone = document.getElementById('phone').value;
                      var position = document.getElementById('position').value;
                         var company = document.getElementById('company').value;
                           var message = document.getElementById('message').value;
                           var link = document.getElementById('link');
enter code here
$.ajax({
                    url: "scripts/index.php",
                    data: {propertyname: name, propertyaddress: address, propertyemail: email, propertyphone: phone, propertyposition: position, propertycompany: company,  propertymessage: message}
                });


                   link.innerHTML = "localhost/leads/lead.php?param="+address; 
            });
        });


    </script>
javascript html ajax
1个回答
0
投票

仅从提交均匀侦听器获取事件参数,即

on.('submit', (e)=>{ 

e.preventDefault(); 
//Your code here

});

0
投票

您可以使用.preventDefault()防止事件的默认行为。

$(document).ready(function() {
    $('#form').on('submit', function(e) {
        e.preventDefault();
        var name = document.getElementById('name').value;
        var address = document.getElementById('address').value;
        var email = document.getElementById('email').value;
        var phone = document.getElementById('phone').value;
        var position = document.getElementById('position').value;
        var company = document.getElementById('company').value;
        var message = document.getElementById('message').value;
        var link = document.getElementById('link');

        $.ajax({
            url: "scripts/index.php",
            data: {
                propertyname: name,
                propertyaddress: address,
                propertyemail: email,
                propertyphone: phone,
                propertyposition: position,
                propertycompany: company,
                propertymessage: message
            }
        });


        link.innerHTML = "localhost/leads/lead.php?param=" + address;
    });
});
热门问题
推荐问题
最新问题