StenW
StenW

Reputation: 2004

Preventing default action in submit event handler is not working properly

I have built a script that seem to work properly, but when the form is submitted the appended data only flashes. I have put return false just before the end. What could be wrong?

$('#blankett_form').submit(function () {
    var id = $(this).find('.update:last').val();
    if (!id) {
        alert('Välj land och region.');
    } else {
        var table = '<table class="table table-hover table-bordered"><thead><tr><th>blanketter.</th><th>datum tillagt.</th></tr></thead><tbody></tbody></table>'
        $('#formsubmit').empty().append(table);
        $.ajax({
            url: 'func/blankett_func2.php',
            data: {
                'id': id
            },
            dataType: 'JSON',
            success: function (data) {
                $.each(data.list, function (index, value) {
                    $('#formsubmit tbody').append(value);
                });
            }
        });
    }
    return false;
});

Upvotes: 0

Views: 79

Answers (1)

Noyo
Noyo

Reputation: 5144

Are you sure the data being returned are <tr>s? If not, the table might not render as you expect, and that may be the cause of what you're seeing.

Upvotes: 1

Related Questions