javascript - IE 11 无法提交 HTML 表单

标签 javascript html forms internet-explorer internet-explorer-11

我有这个 HTML 表单

<form name="nextform" action="anotherpage.php" method="post" enctype="multipart/form-data">
    <input name="pinid" id="pinid" type="hidden">
    <input type="submit" name="submit" id="post" value="Lets Go" class="formButtonMap">
</form>

pinid 使用 JavaScript 动态获取一个值。当它获得一个值时,我会提醒它并且它起作用了。

但是,当我单击 Lets Go 按钮时,没有任何反应。我看到 Internet Explorer 加载了几分钟,然后收到消息“网页没有响应”。如果我点击刷新,它会转到 anotherpage.php 但表单中的值没有到达服务器。

很少显示此消息:

Visual Studio Just-In-Time Debugger

An unhandled win32 exception occured in iexplorer.exe [688]

Possible Debuggers :

New Instance of Microsoft Visual Studio 2012

此行为仅在 Internet Explorer 11.0.2 中出现。该表单适用于旧版本的 Internet Explorer 以及 Chrome 和 Firefox。我在 IE 的控制台中没有收到任何错误。

这是 JavaScript 代码,位于表单上方:

// called when another button is clicked - basicaly is websockets
function save() {
    var so = new WebSocket("ws://localhost:8000");
    so.onerror = function (evt) {
        alert('problem');
    }

    if (sara == 'LINES') {
        so.onopen = function() {
            so.send(JSON.stringify({
                command: 'insertAll',
                name: document.getElementById('name').value
            }));
        }
    }

    if (sara == 'POLY') {
        so.onopen = function() {
            so.send(JSON.stringify({
                command: 'insertHalf',
                name: document.getElementById('name').value
            }));
        }
    }

    so.onmessage = function (evt) {
        var received_msg = evt.data;

        document.getElementById("next").style.display = "block";
        document.getElementById("name").value = "";
        document.getElementById("descr").value = "";
        clearLinks();

        document.getElementById("pinid").value = received_msg;
        alert(document.getElementById("pinid").value); // works

        so.close();
    }
}

我尝试使用 document.getElementById("nextform").submit(); 编辑代码,问题仍然存在。

是我吗?这是一个错误吗?我错过了什么?

最佳答案

我认为这是在 IE 中将表单值设置为空时的错误。

我建议尝试一种不同的方法来重置表单值,我过去使用过这种方法:

document.getElementById('name').parentNode.innerHTML = '';

关于javascript - IE 11 无法提交 HTML 表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20723776/

相关文章:

javascript - 初始化时 Owl-Carousel 超大图像

javascript - JQuery - 如何检查一个跨度是否有一个类,如果不存在则添加一个类

javascript - 检查 Google Analytics 是否(异步)完成了对我页面的跟踪

html - 如何创建链接以将条目添加到日历?

javascript - 在 HTML 表单上使用 GET 作为方法不会附加到 URL 中吗?

PHP 文件上传无法使用 $_FILES 变量,它始终是未定义的

forms - 自定义验证器 Angular 2

javascript - scroll fixed position = jQuery Jank with offset top in safari 浏览器

javascript - Angular : get input values in js function

javascript - 如何在 JQuery 中的更改和加载事件上运行语句?