2014-12-26 1 views
2

jquery_ujs를 사용하여 레일 애플리케이션에서 아약스 양식을 처리합니다. 필자는 ajax : beforeSend 이벤트를 사용하여 remote와 함께 보낼 양식을 변경했다. 나는 그것의 전체 버전을 보려면ajax로 변경 한 후 ajax 요청을 계속 진행하십시오. beforeSend

$('.content>.fr span:last-of-type>a').on "ajax:beforeSend", (xhr, settings) -> 
     swal 
      title: "Are you sure?" 
      text: "You will not be able to undo this!" 
      type: "warning" 
      showCancelButton: true 
      confirmButtonColor: "#DD6B55" 
      confirmButtonText: "Yes, delete it!" 
      closeOnConfirm: false 
     , -> 
      # should send the request here 
      swal "Deleted!", "Department has been deleted.", "success" 
      return 

sweetalert를 사용할 때 나는 this gist에, 그것은 작업의 실행이 확인이 경우 실행을 계속하기 위해 같은 것입니다.

답변

0

는이

$("body").on("click", "#element", function(e) {   
      swal({ 
       title: "Are you sure?", 
       text: "Are you sure?", 
       type: "warning", 
       showCancelButton: true, 
       confirmButtonColor: "#DD6B55", 
       confirmButtonText: "Yes, delete it!", 
       closeOnConfirm: false }, 
       function(){ 
        // ajax goes here 
       }  
      ); 
     }); 

SweetAlert가 beforeSend의 기능은 아약스 요청에 진행을 계속 false를 반환하지 않는, 그래서 만약 사용자의 입력을 기다리는 동안, 스크립트 실행이 중지되지 않습니다 자바 스크립트 확인 다르다 좋아한다.

+0

내 두 번째 레일 프로젝트에서 지금은 레일에서 개발 해본 적이 있기 때문에 아약스조차 시도하지 않았습니다. 나는 UJS'remote : true' 만 사용한다. –