2013-08-07 1 views
0

이것은 세 브라우저 모두 문제없이 양식을 제출할 수있는 유일한 방법입니다. 이것이 왜 그렇게 명백한 이유가 있습니까? 이것에 대한보다 우아한 해결책? 나는 jQuery 1.9를 사용하고있다. 다른 곳의 코드가 IE와 Firefox를 통해 제출하기에 충분하기 때문에 Chrome은 이상한 사람입니다.크롬, IE 8 및 파이어 폭스 같은 양식을 제출하는 wierd 방법

function submitFormByPost(actionName){ 
    $("#eventAction").val(actionName); 

    var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1; 
    if(is_chrome){ 
      document.getElementById('myForm').method='POST'; 
      document.getElementById('myForm').submit(); 
    } 
    else{ 
      document.forms[0].method='POST'; 
      document.forms[0].submit(); 
    } 
} 

답변

0

또한 다른 사람에서 작동합니다 크롬에서 작동하는 방법 :

function submitFormByPost(actionName){ 
    $("#eventAction").val(actionName); 
    var frm = document.getElementById('myForm'); 
    frm.method = 'POST'; 
    frm.submit(); 
} 

또는 jQuery를 모든 방법 사용 : 시도

function submitFormByPost(actionName){ 
    $("#eventAction").val(actionName); 
    $('#myForm').attr('method', 'POST').submit(); 
} 
0

이것은 일부 구형 Chrome 버전의 호환성을위한 것입니다. 일반적으로 document.forms[0]은 다른 브라우저에서와 마찬가지로 Chrome에서도 작동합니다. 확인하는 가장 쉬운 방법은 Chrome 콘솔을 열고 console.log(document.forms[0]);이라고 작성하면됩니다.

3

jQuery는 양식을 제출할 때 브라우저 간 방법을 제공해야합니다. 그래서 그냥 사용

var $form = $("#myForm"); 
$form.attr('method', 'post'); 
$form.submit();