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

jquery

Solution

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();`).

Problem

I changed my coding style for php and jQuery, but my Registration ``` $("#reg_form_company").bind("submit", function() { $.fancybox.showActivity(); $.ajax({ type : "POST", cache : false, url : $(this).attr('action'), data : $(this).serializeArray(), success : function(data) { $(".printArea").empty().append(data).css('visibility','visible'); } }); return false; }); ``` Then this is my Form ``` <form id="reg_form_company" action="index.php?module=register&actionregister" method="post" > <input>[...]</input> </form> ``` Then after clicking the "Submit" button, it doesn't work, I assume that somebody can help me to solve this problem, coz the $.ajax might confuse about POST(for inputs) and the GET(for the parameters of the "action" form) I appreciate for your help, you can also modify the entire jQuery code if it's required. Sorry guys for not including the #reg_form_company, and the fancybox

Original source