jQuery ajax请求不会触发并冻结页面

时间:2014-09-17 11:16:42

标签: javascript jquery ajax

我遇到了jquery ajax请求的一个主要问题。 Tt似乎冻结了当前的页面 我也试过使用* $。pos * t,但它也做了同样的事情。我环顾四周,但似乎无法找到确切的答案。

代码:

var sd = $('#start-date'),
    ed = $('#end-date'),
    n = $('#name'),
    o = [],
    m = $('#multi').prop('checked');

if ($.trim(n.val()) !== '') {
    $('.option').each(function () {
        var el = $(this);
        if ($.trim(el.val()) !== '') {
            o.push(el.val())
        }
    });

    if (o.length > 1) {
        alert(1);
        $.ajax({
            url: "pageurl",
            type: "POST",
            data: {
                name: n,
                options: o,
                multiple: m,
                start: sd,
                end: ed
            },
            dataType: "json",
            success: function (data) {
                if (data.success !== undefined) {
                    if (data.success == '1') {
                        alert('worked');
                    } else {
                        displayWarning(data.reason);
                    }

                } else {
                    displayWarning('We couldn\'t process your request at this time. Please try again later');
                }
            },
            error: function () {
                displayWarning('We couldn\'t process your request at this time. Please try again later');

            }
        });
    } else {
        displayWarning('please enter at least 2 options');
    }

} else {
    displayWarning('Please provide a name for the poll');
}

非常感谢任何帮助

谢谢

1 个答案:

答案 0 :(得分:0)

json无效应如下所示:

var sd = $('#start-date').val(),
ed = $('#end-date').val(),
n = $('#name').val(),
o = [],
m = $('#multi').prop('checked');

data: {
    "name": n,
    "options": o,
    "multiple": m,
    "start": sd,
    "end": ed
}