Javascript - 原型:表单上的 Event.observe 不适用于 IE

发布于 2024-09-27 16:09:02 字数 1237 浏览 2 评论 0原文

我有这个 JS,它从服务获取 XML 响应,它是 True 或 False,那么脚本应该捕获提交并从服务获取响应。 问题是我发现它不起作用,因为当我提交时,我在 IE (6/7/8) 上看到 XML 响应,而脚本应该捕获它并验证 XML 响应。

<div id="eventForm" style="display:none;">
    Event.observe('formDataPersonal', 'submit', function(event) {
    $('formDataPersonal').request({
        onSuccess: function(t) {
            var xml  = t.responseXML.documentElement;
            var stateNode = '';
            var msgNode = '';
            if (navigator.appName == "Microsoft Internet Explorer"){
                stateNode = xml.childNodes[0].nodeValue.toLowerCase();
                msgNode = xml.childNodes[1].nodeValue;
            }else{
                stateNode = xml.childNodes[0].textContent.toLowerCase();
                msgNode = xml.childNodes[1].textContent;
            }
            if (stateNode == 'true'){
                $('transparentDiv').style.display='none';
                $('popup').style.display='none';
                validateIntegrationPopup();
            }else{
                var error = msgNode;
                if (error != ''){
                    $('interfase').innerHTML = error;
                }
            }
        }
     })
    });
</div>

我将不胜感激您的帮助。

I have this JS which gets a XML response from a service, its a True or a False, well the script should catch the submit and get the response from the service.
The problem is that I see that its not working because when I do the submit, I see the XML response on IE (6/7/8), when the script should have catched it and validated the XML response.

<div id="eventForm" style="display:none;">
    Event.observe('formDataPersonal', 'submit', function(event) {
    $('formDataPersonal').request({
        onSuccess: function(t) {
            var xml  = t.responseXML.documentElement;
            var stateNode = '';
            var msgNode = '';
            if (navigator.appName == "Microsoft Internet Explorer"){
                stateNode = xml.childNodes[0].nodeValue.toLowerCase();
                msgNode = xml.childNodes[1].nodeValue;
            }else{
                stateNode = xml.childNodes[0].textContent.toLowerCase();
                msgNode = xml.childNodes[1].textContent;
            }
            if (stateNode == 'true'){
                $('transparentDiv').style.display='none';
                $('popup').style.display='none';
                validateIntegrationPopup();
            }else{
                var error = msgNode;
                if (error != ''){
                    $('interfase').innerHTML = error;
                }
            }
        }
     })
    });
</div>

I would be grateful for the help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷月断魂刀 2024-10-04 16:09:02

我认为问题可能是“IE”看不到提交事件,因此它最终只是正常提交​​表单:

请参阅:https://rails.lighthouseapp.com/projects/8994/tickets/4411-railsjs-on-bodyobservesubmit-but -提交-doesnt-bubble-in-ie

I think the problem may be that 'IE' does not see the submit event so it ends up just submitting the form normally:

See: https://rails.lighthouseapp.com/projects/8994/tickets/4411-railsjs-on-bodyobservesubmit-but-submit-doesnt-bubble-in-ie

原谅过去的我 2024-10-04 16:09:02

这是一个老问题,但我设法将其作为 Google 搜索中的第二个结果,因此:

您没有阻止提交事件通过浏览器,这就是即使事件处理程序也提交表单的原因附于其上。添加 event.stop()

<div id="eventForm" style="display:none;">
    Event.observe('formDataPersonal', 'submit', function(event) {
       event.stop();
       $('formDataPersonal').request({
          // .... code ....
       });
    });
</div>

This is an old question, but I managed to get it as my second result in a Google search, so:

You're not stopping the submit event from going through to the browser, which is why the form is submitting even though the event handler attached to it. Add in an event.stop():

<div id="eventForm" style="display:none;">
    Event.observe('formDataPersonal', 'submit', function(event) {
       event.stop();
       $('formDataPersonal').request({
          // .... code ....
       });
    });
</div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文