简体   繁体   English

Internet Explorer 11-AJAX呼叫未触发

[英]Internet Explorer 11 - AJAX Call not firing

I am stuck in the middle of a bug. 我陷入了错误。 I began to use BrowserStack to validate my current project against Windows IE and EDGE and I got a particular issue with IE 11. 我开始使用BrowserStack来针对Windows IE和EDGE验证当前项目,而IE 11出现了一个特殊问题。

I first got an issue that I solved which was that FormData did not have any .get() methods, and I used the NPM formdata-polyfill for that. 我首先解决了一个问题,即FormData没有任何.get()方法,为此我使用了NPM formdata-polyfill。

I am working on a native JS login form, using FormData and XMLHTTPRequest, and it seems that the AJAX call is not firing at all. 我正在使用FormData和XMLHTTPRequest处理本机JS登录表单,似乎AJAX调用根本没有触发。

When clicking on the submit button, instead of sending to my particular login URL, the POST request is fired to the current page itself. 单击提交按钮时,POST请求会发送到当前页面本身,而不是发送到我的特定登录URL。

So, obviously, no event is catched and no JavaScript is executed. 因此,很明显,没有捕获任何事件,也没有执行JavaScript。

My JavaScript is compiled using WebPack, and the lines I use to get the login form and attach proper events to it are the following : 我的JavaScript是使用WebPack编译的,我用于获取登录表单并将适当的事件附加到其上的行如下:

    var formLogin = document.querySelector( "#form-login" );

    if ( formLogin !== null )
    {
        var email    = document.getElementById( "email" );

        formLogin.addEventListener( "submit", _.validateLoginForm );
        _.formInstance.init( formLogin );

        _.inputUtil.disableField( '#btn-submit-email' );
        _.inputUtil.disableField( '#btn-submit-password' );

        utils.addAndDispatchEvent( '#email', 'input', _.inputUtil.disableSubmitIfFieldIsEmpty( '#btn-submit-email' ) );
        utils.addAndDispatchEvent( '#password', 'input', _.inputUtil.disableSubmitIfFieldIsEmpty( '#btn-submit-password') );

        email.addEventListener( "invalid", _.onInvalidEmail );
    }

``` ```

The JS file is properly loaded to. JS文件已正确加载到。

I do not get where it can come from as it works well on any others browsers ( including Edge after I got the polyfill ). 我不知道它的来源,因为它在任何其他浏览器(包括polyfill之后的Edge)上都能很好地工作。

If you have any ideas, let me know ! 如果您有任何想法,请告诉我!

Thanks for listening. 谢谢收听。

My issue here was that I needed to override my call to different e.preventDefault() by e.preventDefault ? e.preventDefault() : ( e.returnValue = false ); 我的问题是我需要通过e.preventDefault ? e.preventDefault() : ( e.returnValue = false );覆盖对其他e.preventDefault()e.preventDefault ? e.preventDefault() : ( e.returnValue = false ); e.preventDefault ? e.preventDefault() : ( e.returnValue = false );

Which is better supported on IE. 在IE上更好地支持。

Got this information from the following post : event.preventDefault() function not working in IE 从以下帖子中获得了此信息: event.preventDefault()函数在IE中不起作用

Then I got aditionnal issues with the Event and CustomEvent class not properly supported so I added a few polyfills by adding Babel Transpiler to avoid using ES2015 but compatible JS. 然后,我遇到了Event和CustomEvent类不受正确支持的问题,因此通过添加Babel Transpiler来避免使用ES2015但兼容的JS,从而添加了一些polyfills。

Still having some issues with supporting IE 11 completely but this one is fixed. 完全支持IE 11仍存在一些问题,但此问题已解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM