2012-08-24 2 views
0

확인 대화 상자를 표시하고 사용자가 '계속'을 누르면 양식이 제출됩니다. jquery 대화 상자를 사용하여 ajax 양식 제출

는 jQuery 코드입니다 :

$(document).ready(function() { 
    $('#submit').click(function() { 

     $('#confirmation-dialog').dialog('open'); 
     return false; // prevents the default behaviour 
    }); 
    $('#confirmation-dialog').dialog({ 
     autoOpen: false, width: 400, resizable: false, modal: true, //Dialog options 
     buttons: { 
      "Continue": function() { 
       $(this).dialog('close'); 
       var form = $('transferForm', this); 
       $(form).submit(); 
        return true; 
        }, 

      "Cancel": function() { 
       $(this).dialog("close"); 
       return false; 
      } 
     } 
    }); 
}); 

그리고 이것은 형태 :

@using (Ajax.BeginForm("Transfer", "Location", null, new AjaxOptions 
{ 
    UpdateTargetId = "update-message", 
    InsertionMode = InsertionMode.Replace, 
    HttpMethod = "POST", 
    //OnBegin = "ajaxValidate", 
    OnSuccess = "updateSuccess" 

}, new { @id = "transferForm" })) 
{ 

<div style="width:600px;"> 
<div class="editorLabel"> 
    @Html.LabelFor(m => m.FromEmail) 
</div> 
<div class="editorText"> 
    @Html.TextBoxFor(m => m.FromEmail) 
</div> 
<div class="clear"></div> 
<div class="editorLabel"> 
    @Html.LabelFor(m => m.ToEmail) 
</div> 
<div class="editorText"> 
    @Html.TextBoxFor(m => m.ToEmail) 
</div> 
<div class="clear"></div> 
<p> 
    <input type="submit" name="submit" value="Transfer" class="btn" id="submit"/> 
</p> 
</div> 
} 
<div id="update-message"></div> 
<div id="commonMessage"></div> 
<div id="confirmation-dialog"> 
<p>Are you sure you want to proceed with transfer ? 

</p> 
</div> 

그러나 확인 후, 양식이 제출되지 않습니다. 무엇이 잘못 될 수 있습니까 ?? 어떤 아이디어?

var form = $('transferForm', this); 
$(form).submit(); 

에 :

+0

잘못된 jquery 선택기를 사용하고 있습니까? var form = $ ('transferForm', this); 하지 말아야 var form = $ ('# transferForm', this); – aravind

답변

1

봅니다이 변경 대화 상자 이벤트 핸들러 내부 this

$("#IDofForm").submit(); 

아마 당신이가하는 생각을 참조 does'nt, 당신은 아마이 없습니다 transferForm 태그가있는 요소 (셀렉터 앞에 # 또는 .을 사용하지 않을 때 타겟팅하는 요소)?

+0

네, 맞습니다. '이'일은 여기서 작동하지 않습니다. $ ("# IDofForm"). submit(); - 이것은 작동합니다. 감사. – kandroid