Form submission using jQuery ajax

后端 未结 4 1994
太阳男子
太阳男子 2021-01-23 19:59

Form is not submit using ajax.form submit on click li. Give me some solution

My js code is here

$(document).ready(function(){

$(\'#sortable li\').click(         


        
相关标签:
4条回答
  • 2021-01-23 20:26

    You should provide your HTML too in your question, but as far as i can see, you have event in event callbacks with actually nothing to initiate the submit event. So basically you should consider something like this :

    $(document).ready(function(){
    
        $('#sortable li').click(function() {
            event.preventDefault();
            var formdata = $("#frmgallery").serialize();
            alert(formdata);
            $.ajax({
                type: "POST",
                url: "gallery.php",
                data: formdata,
                success: function(){alert('success');}
            });
        });
    
    });
    
    0 讨论(0)
  • 2021-01-23 20:27

    Have you tried return false at the end of your submit function?

        $("#frmgallery").submit(function(e) {
            e.preventDefault();
            var formdata = $(this).serialize();
            alert(formdata);
            $.ajax({
                type: "POST",
                url: "gallery.php",
                data: formdata,
                success: function(){alert('success');}
                error: function(){alert('error');}
            });
            return false;
        });
    $('#sortable li').click(function() {
    
         $("#frmgallery").submit();
    });
    

    Also post what you get from $.ajaxcall

    0 讨论(0)
  • 2021-01-23 20:40
    $("#frmgallery").ajaxForm({url: 'gallery.php', type: 'post'})
    

    Have you tried return false at the end of your submit function?

        $("#frmgallery").submit(function(e) {
            e.preventDefault();
            var formdata = $(this).serialize();
            alert(formdata);
            $.ajax({
                type: "POST",
                url: "gallery.php",
                data: formdata,
                success: function(){alert('success');}
                error: function(){alert('error');}
            });
            return false;
        });
    $('#sortable li').click(function() {
    
         $("#frmgallery").submit();
    });
    
    0 讨论(0)
  • 2021-01-23 20:44

    You can use the ajaxForm/ajaxSubmit functions from Ajax Form Plugin or the jQuery serialize function.

    Example:

    $("#frmgallery").ajaxForm({url: 'gallery.php', type: 'post'})
    

    or

    $("#frmgallery").ajaxSubmit({url: 'gallery.php', type: 'post'})
    

    ajaxForm will send when the submit button is pressed. ajaxSubmit sends immediately.

    0 讨论(0)
提交回复
热议问题