2011-09-20 2 views
0

Enter 키는 아래 양식을 게시하는 데 사용됩니다. Enter 키를 누르면 get 요청을받습니다. IE9 : 첫 번째 입력은 받기, 두 번째 입력은 post, 세 번째는 send 요청 받기 등을 입력합니다.Enter 키를 누르는 대신 IE9에서 POST 메서드를 호출하는 이유는 무엇입니까?

Enter 키를 누른 경우 게시 요청 만 보내는 방법은 무엇입니까? Firefox에서는 게시물 요청 만 올바르게 전송됩니다.

<form id="Form" method='post' target='DocumentRegisterReportpdf' 
    action='/erp/Report/Render?_entity=DocumentRegisterReport'> 
... form fields 

<select class="ui-widget-content ui-corner-all" id="_Report" name="_Report" size="10"> 
<option selected="selected" value="AKART001">Report1</option> 
<option value="A3001">Report2</option> 
<option value="A3003">Report3</option> 
</select> 

<input id='_submit' type='submit' value='Show PDF' /> 
</form> 
    <script type="text/javascript"> 
     $(function() { 
      $('#_Report').keypress(function (e) { if (enter(e)) { $('#Form')[0].submit(); cancel(e); } }); 
      $('#_submit').focus(); 
     }); 

function enter(e) { return e.keyCode === $.ui.keyCode.ENTER && !e.ctrlKey && !e.altKey; } 

function cancel(evt) { 
    evt.returnValue = false; 
    evt.keyCode = 0; 
    evt.cancelBubble = true; 
    evt.preventDefault(); 
    evt.stopPropagation(); 
} 
    </script> 

답변

0
$('#_Report').keypress(function (e) { 
    if (enter(e)) 
     { 
      var action = $('#Form').attr('action'), 
       separator = action.indexOf('?') == -1 ? '?' : '&', 
       url = action + separator + $('#Form').serialize(), 
       post_or_get = 'post'; 
      $.ajax({ 
       url : url, 
       method : post_or_get, 
       success : function(data){ 
        // this is the callback :) 
       } 
      }); 
     } 
}); 

하거나, 양식을 복제 post에서 get에이 방법의 변경 및 제출 수 :

$('#_Report').keypress(function (e) { 
    if (enter(e)) 
     { 
      var post_or_get = 'post'; 
      $('#Form') 
       .clone() 
       .attr('method', post_or_get) 
       .submit(); 
     } 
}); 
+0

코드를 전송합니다에만 요청을 얻을. 나는 단지 게시물 요청을 보내달라고 요청했다. 문제는 입력을 누르면 알 수없는 이유로 순차적으로 요청을 게시하고 게시한다는 것입니다. 'post' 요청을 보내는 방법은? – Andrus

+0

업데이트를 참조하십시오. 게시 및 가져 오기 방법을 모두 사용할 수 있습니다. –

+0

IE9에서 업데이트 된 메서드를 시도했습니다. ajax 호출은 매회 get 요청을 보냅니다. clone() 메서드가 요청을 보내지 않으면 submit() 호출이 무시됩니다. 입력시 게시물 요청을 보내는 방법은 무엇입니까? – Andrus

관련 문제