jQuery提交Ajax

I can't seem to make this to work. I'm trying to submit form using jquery dialog and I want to receive in php so I can use $_POST.

Any idea?

HTML:

<div id="table_rows_form">
    <form id="fieldsform" action="system/create">
        <label for="fields">How many fields are needed?</label>
        <input type="text" id="fields" name="fields" />
        <button type="submit">Submit</button>
    </form>
</div>

Javascript:

$(document).ready(function() {
    $('#table_rows').on('click', function() {
        $('#table_rows_form').dialog({
            open: function() {
                $(this).find('[type=submit]').hide();
            },
            draggable: true,
            modal: true,
            resizable: false,
            closeOnEscape: false,
            width: 'auto',
            minHeight: 235,
            title: 'Number of Fields',
            dialogClass: 'no-close',
            buttons: {
                "Send": function() {
                    $('#fieldsform').submit(function(event) {
                        var formData = {
                            'fields': $('input[name=fields]').val()
                        };
                        $.ajax({
                            type: 'POST',
                            url: $('#fieldsform').attr('action'),
                            data: formData,
                            dataType: 'json',
                            encode: true
                        });
                    });
                },
                "Cancel": function() {
                    $(this).dialog('close');
                }
            }

        });
        return false;
    });
});

PHP:

print_r($_POST);

The dialog opens correctly but when pressing send button doesn't do anything and doesn't gives any error at the console. Any idea about the error? I'm a newbie with jquery.

You're just adding a submit handler with your code $('#fieldsform').submit( ... ) so it doesn't trigger anything.

Rather, you should do that on document ready, and in the click handler for "Send" button, call $('#fieldsform').submit();