sourcecode

IE9은 F12를 친 후에만 아약스 호출을 올바르게 수행합니다.

copyscript 2023. 9. 1. 21:15
반응형

IE9은 F12를 친 후에만 아약스 호출을 올바르게 수행합니다.

JSP 페이지(jQuery 1.7.2)에 다음과 같은 jQuery 코드가 있습니다.

   function Header() {
      this.add = function ( parentDiv, leftToolbar, rightToolbar ) {
         hbHeader = Handlebars.compile( $( "#hb-header" ).html() );

         $( parentDiv ).html( hbHeader( {user:{tenantDescription:"", firstName:"", lastName:""},
            leftTB:null, rightTB:null } ) );

         $.ajax( {
            url:"${pageContext.request.contextPath}/services/login/sessionUser",
            type:"POST",
            async:true,
            success:function ( result ) {
               app.user = result;
               var ltHtml;
               var rtHtml;
               if ( leftToolbar ) {
                  ltHtml = new Handlebars.SafeString( leftToolbar );
               }
               if ( rightToolbar ) {
                  rtHtml = new Handlebars.SafeString( rightToolbar );
               }
               $( parentDiv ).html( hbHeader( {user:app.user,
                  leftTB:{
                     html:ltHtml,
                     hidden:leftToolbar == null
                  },
                  rightTB:{
                     html:rtHtml,
                     hidden:rightToolbar == null
                  }
               } ) )
            },
            error:function( jqXHR, textStatus, errorThrown ) {
               alert("error in ajax");
            }
         } );
      }
   }

이 코드가 실행되기 전에,ajaxSend그리고ajaxError수신기가 등록되었습니다.이와 같은 경우:

  $( "#log-window" ).ajaxSend( function ( event, jqXhr, ajaxOptions ) {
     console.log( "handling an ajax request adding username and password to the header" );
     jqXhr.setRequestHeader( 'username', $.cookie( 'username' ) );
     jqXhr.setRequestHeader( 'password', $.cookie( 'password' ) );
  } );
  $( "#log-window" ).ajaxError( function ( errorThrown, xhr, failedReq, textStatus ) {
     alert("error in "+failedReq.url);
     if ( textStatus == 'timeout' ) {
        if ( !failedReq.tryCount ) {
           failedReq.tryCount = 1;
           failedReq.retryLimit = 3;
        }
        if ( failedReq.tryCount++ <= failedReq.retryLimit ) {
           //try again
           $.ajax( failedReq );
           return;
        }
        throw 'Es wurde ' + failedReq.retryLimit + ' Mal versucht. Die Verbindung scheint nicht zu funktionieren.';
        return;
     }
     if ( xhr.status == 500 ) {
        if ( $.cookie( 'pageRefreshed' ) == null ) {
           $.cookie( 'pageRefreshed', 'true', { expires:10000 } );
           location.reload();
        }
        throw 'Der Server hatte ein Problem. Bitte melden Sie den Fehler and den Systemadministrator';
     } else if ( xhr.status == 401 ) {
        if ( failedReq.url != "${pageContext.request.contextPath}/services/login" ) {
           var loginData = {
              username:$.cookie( 'username' ),
              password:$.cookie( 'password' )
           };
           loginAttempt( failedReq, loginData );
        }
     } else {
        throw 'Oops! There was a problem, sorry.';
     }
  } );

전체 페이지는 http://alpha.sertal.ch:8181/VisionWeb/data-details/ #data:12300923에서 액세스할 수 있습니다.

원한다면 로그인할 수도 있습니다.사용자: ft03 비밀번호: 비밀번호

Ajax 호출이 처음 이루어지면 사용자가 로그인하지 않았기 때문에 401 오류가 발생합니다. 여기서 IE가 실패합니다.ajaxSend수신기가 호출되었지만ajaxError아닙니다.에서 오류 콜백을 설정한 경우$.ajax그 자체로 그것은 또한 불리지 않습니다.

실제 브라우저(Firefox, Chrome, Opera)로 페이지를 열면 잘 작동하고 암호를 요청합니다.IE는 당신이 누르지 않는 한 그렇지 않습니다. 이 경우 사이트도 예상대로 작동합니다.

정말 이상합니다.콘솔이 열린 상태에서 페이지를 로드하면 작동합니다.콘솔을 닫으면 빈 머리글만 표시됩니다.페이지가 로드되면 콘솔을 닫을 수 있으며 계속 로드됩니다.

저는 이것을 다양한 기계에서 테스트했고 같은 결과를 얻었습니다.

그것은 나를 미치게 해요.F12로 디버거를 열면 정상적으로 작동하기 때문에 디버그할 수 없습니다.

나는 아약스 콜백이 이루어지지 않은 것을 알고 있습니다. 왜냐하면 나는 그것을 넣었기 때문입니다.alert("I got so far")여러 위치의 선

만약 누군가가 단서를 가지고 있다면, 그것은 매우 환영할 일입니다.

의 모든 인스턴스console.log()개발자 모드가 아닌 IE9에서 작동하려면 스크립트에서 제거해야 합니다.

업데이트 이 답변이 몇몇 사람들에게 도움이 되었다니 기쁩니다.HTML5 Bilerplate에서 사용해온 간단한 솔루션으로 이 답변을 업데이트하려고 생각했습니다.

// Avoid `console` errors in browsers that lack a console.
(function() {
    var method;
    var noop = function () {};
    var methods = [
        'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
        'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
        'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
        'timeStamp', 'trace', 'warn'
    ];
    var length = methods.length;
    var console = (window.console = window.console || {});

    while (length--) {
        method = methods[length];

        // Only stub undefined methods.
        if (!console[method]) {
            console[method] = noop;
        }
    }
}());

코드 앞에 놓으면 콘솔이 없는 브라우저에서 콘솔 오류를 방지하는 데 도움이 됩니다.

IE에서 console.log가 개발자 모드 외부에 정의되어 있지 않습니다.저는 그냥 변수를 만드는 것을 좋아합니다.

var console = {log: function(){}};

디버깅을 하지 않을 때를 위해.

저는 이 문제가 있었고 모든 콘솔 참조를 스크립트에 주석을 달았지만 IE에서만 여전히 실패했습니다(11).해결책은 AJAX 호출에 캐시 오류를 추가하는 것이었습니다.

$.ajax({
        **cache: false,**
        type : 'GET',})

모든 입력에는 autocomplete="off" 속성이 있습니다.

정말로 시간을 절약했습니다, IE 11에서, 우리는 캐시를 넣어야 합니다: 이 문제를 해결하기 위해 아약스를 잊기 위해 거짓.

언급URL : https://stackoverflow.com/questions/11147553/ie9-makes-ajax-call-correctly-only-ofter-hitting-f12

반응형