2012-12-01 3 views
3

다음은 스크립트입니다. 그것은 다른 모든 브라우저에서 잘 작동하므로 캐시 문제이지만 실제로는 아니라고 생각했습니다. 나는 몇 시간 동안 내 머리를 부딪 치고 있었고 아무것도 작동하지 않았다.Ajax가 IE에로드되지 않습니다

$.ajaxSetup({ 
    cache: false 
}); 

$("#send").live('click', function() { 
    console.log("AAAAA"); 
    $("#loader").show(); 
    $form = $('#reservationForm'); 

    $inputs = $form.find('input[name^="entry"]'), 
    serializedData = $('#reservationForm :input[name^="entry"]').serialize(); 

    console.log(serializedData); 
    serializedData += "&pageNumber=0&backupCache=1&submit=Submit"; 

    // fire off the request to /form.php 
    $.ajax({ 
     url: "https://docs.google.com/spreadsheet/formResponse?formkey=d", 
     // url: "https://docs.google.com/spreadsheet/formResponse?formkey=d;ifq", 
     type: "post", 
     data: serializedData, 
     // callback handler that will be called on success 
     success: function (response, textStatus, jqXHR) { 
      // log a message to the console 
      console.log("Hooray, it worked!"); 
      $("#loader").hide(); 
      document.getElementById('error<?php echo"$uname";?>').innerHTML = error; 
      $("#success").fadeIn(); 
      setTimeout(function() { 
       $("#success").fadeOut(); 
      }, 5000); 
     }, 
     // callback handler that will be called on error 
     error: function (jqXHR, textStatus, errorThrown) { 
      // log the error to the console 
      console.log("The following error occured: " + textStatus, errorThrown); 
      alert('Due to an unknown error, your form was not submitted, please resubmit it or try later.'); 
     }, 
     // callback handler that will be called on completion 
     // which means, either on success or error 
     complete: function() { 
      // enable the inputs 
      $inputs.removeAttr("disabled"); 
     } 
    }); 

    // prevent default posting of form 
    event.preventDefault(); 

}); 
+0

내가 읽을 수있는 자바 스크립트를 만들어 – GottZ

+0

코드를 내가 그것을 편집하는 방법을 시도 고려할 수있다 "missplaced 삭제했습니다 – GottZ

+0

당신은 – mikipero

답변

2

IE에서 개발자 도구 (F12 키를 열면)를 열면 console.log를 사용할 수 있습니다. 코드를 켜거나 코드에서 경고를 사용하십시오. 또는 try catch를 사용하십시오.

try{ 
    console.log('worked') 
} 
catch(err){ 
} 

그리고 이벤트 변수가 정의되지 않은 경우 확인 할 수 있습니다 :

event= event || window.event; 
event.preventDefault(); 
+1

예,'console.log'는 IE에서 자바 스크립트를 해독합니다. 또 다른 대안은 H5BP (https://github.com/h5bp/html5-boilerplate/blob/master/js/plugins.js)의 스크립트와 같은 것을 사용하는 것입니다.), 아무 것도 보이지 않기 때문에 오류가 발생하지 않는 브라우저에서 메서드를 정의합니다. – ultranaut

+0

플러그인 js를 사용하는 방법에 대한 약간의 예가 큰 도움이 될 것입니다. 미리 감사드립니다. – emuigai

0

당신이 핸들러에서 "이벤트"선언을 추가하지 않는 스크립트의 시작 부분에서 :

$("#send").live('click', function() { 

은 다음과 같아야합니다

$("#send").live('click', function (e) { 

그리고 스크립트의 끝에 변수 이벤트에 대한 참조가 : 나는 IE 글로벌 이벤트 객체의 'preventDefualt'기능을 (당신이 참조하는)가 발생하지 않는 것을 생각

// prevent default posting of form 
event.preventDefault(); 

이 함수가 jQuery에 의해 전달 된 "e"이벤트 객체에 추가됩니다. 어쨌든 "이벤트가 정의되지 않았습니다"라는 다른 모든 브라우저에서도 실패합니다. 너무 이것보십시오 :

// prevent default posting of form 
e.preventDefault(); 

추가 참고 : jQuery를 팀은 현재 "라이브"이벤트 바인딩 기능의 사용을 억제하는 대신 당신이 "에"기능에 해당 양식을 사용합니다.

0

IE는 ajax에서 응답의 콘텐츠 유형을 이해하지 못합니다. 그래서 귀하의 dataType 값을 요청에 넣어 줘야합니다. 예 : -

dataType: ($.browser.msie) ? "text" : "xml" 
관련 문제