0

以下代码在 FF 和 Chrome 中运行良好: 通过 Ajax 发布表单并出现模式窗口。在 IE9 中,出现模态窗口但不发布表单。

Javascript:

$(document).ready(function() {
$(document).ajaxStart(function(){
    $('#thanks').modal();
});

$('.ajaxform').submit(function () {
    $.ajax({
        url: $(this).attr('action'),
        type: $(this).attr('method'),
        dataType: 'html',
        data: $(this).serialize(),
        success: function (data) {},
        error: function () { }
    });
    return false;
});

});

HTML:

<form method="post" action="https://www.example.com/post.php" class="ajaxform">
<label>First name*</label>
                    <input type="text" name="fname" required>

                    <label>Last name*</label>
                    <input type="text" name="lname" required>

                    <label>Email address*</label>
                    <input type="email" name="email" required>

                    <label>Phone number*</label>
                    <input type="tel" name="phone" required>
<input class="btn btn-primary" type="submit" value="Submit Request" role="button" href="#thanks">
4

2 回答 2

1

您能否检查一下您的提交事件处理程序是否实际上在 IE 中被调用?我要问的原因是 jQuery .submit()文档指出:

“JavaScript 提交事件不会在 Internet Explorer 中冒泡。但是,从 jQuery 1.4 开始,依赖事件委托和提交事件的脚本将在浏览器中始终如一地工作,这已经规范了事件的行为。”

因此,根据您使用的 jQuery 版本,这可能是一个问题……此外,使用 Fiddler 或控制台检查 Ajax 调用是否实际离开浏览器可能会给出提示。

干杯,亚历克斯

于 2013-02-25T21:13:58.157 回答
0

我看不到您的 ajax 调用在哪里将其变为实际帖子。如果它是一个获取,您可能必须在 IE 中禁用缓存。jQuery ajax 调用有一个设置:cache: false.

$('.ajaxform').submit(function () {
    $.ajax({
        cache: false,
        url: $(this).attr('action'),
        type: $(this).attr('method'),
        dataType: 'html',
        data: $(this).serialize(),
        success: function (data) {},
        error: function () { }
    });
    return false;
});
于 2013-02-25T15:53:00.843 回答