在 IE7 中提交不接受函数返回



我正在尝试通过ajax提交表单,无论我做什么提交都会根据正常的post函数在IE7中触发页面重新加载。

我试过什么

    // Example function / attempt 0
<script>
    function FunctionName() {
        $.ajax({
           type: "POST",
           blah: "blah"
        });
        return false;
    }
</script>
// attempt 1
<form onsubmit="return FunctionName()">
// attempt 2
<form onsubmit="FunctionName(); return false;">
// attempt 3
$("#form id").submit(FunctionName);

我最终得到的是通过 ajax 的乱码输入和每次页面刷新。

http://jsfiddle.net/a6WR5/

我认为您只需要将return FunctionName()包含在函数中即可。看小提琴。

此外,您不需要文档就绪调用。

你的代码有太多错误。这是应该可以工作的代码:

<script>
function Name() {
    $.ajax({
       type: "POST",
       url: "/echo/html/"
    });
    return true;
}
</script>
<form onsubmit="return Name()">
    <input type="submit" />
</form>

为了您的方便,这里也: http://jsfiddle.net/jasdeepkhalsa/YQN6K/5/

最新更新