How to use jQuery .ajax to my form's action

前端 未结 5 2246
你的背包
你的背包 2021-02-08 12:54

I changed my coding style for php and jQuery, but my Registration

$(\"#reg_form_company\").bind(\"submit\", function() {
    $.fancybox.showActivity();
    $.aj         


        
5条回答
  •  孤独总比滥情好
    2021-02-08 13:12

    You need to do something like this: http://jsfiddle.net/xSJTs/2/

    $('form').on('submit',function(e){
        e.preventDefault();
        $.ajax({
            type     : "POST",
            cache    : false,
            url      : $(this).attr('action'),
            data     : $(this).serialize(),
            success  : function(data) {
                $(".printArea").empty().append(data).css('visibility','visible');
            }
        });
    
    });
    

    You have to use serialize() instead of serializeArray(). serializeArray() creates a JavaScript-object, serialize() creates a query-string.

    Serialize: http://api.jquery.com/serialize/

    SerializeArray: http://api.jquery.com/serializeArray/

    Basically you wait until the form is submitted and then you interrupt it (e.preventDefault();).

提交回复
热议问题