2011-03-31 4 views
1

나는 grails를 처음 사용하며 다음과 같은 문제가 있습니다.ajax 호출에서 하나의 컨트롤러 동작을 다른 컨트롤러 동작으로 리디렉션

컨트롤러 1에서 ajax 호출을 통해 action1을 호출합니다. 이제 controller2에있는 action2로 리디렉션하려고합니다.

아래에 지정된대로 ...하지만 작동하지 않는 것 같습니다. 제발 도와주세요 !!

class controller1 { 
    def action1 = { 
     redirect(controller:'controller',action:'action2') 
    } 
}  

class controller2{ 
    action2{ 

    } 
} 
+0

쉬운 예제처럼 보이지만 확실하게 싶습니다. action2는 def action2 = {...} 여야합니다. 맞습니까? 컨트롤러의 이름은 예를 들어 UserController와 같아야합니다. –

답변

0

redirect() 대신 render()을 사용할 수 있습니다.

1

당신이 당신의 아약스 콜백 기능, 예를 통해 리디렉션을 수행해야합니다 당신이 당신의 controller1의 조치 1 예

$.ajax({ 
     type: "POST", 
     url: "${createLink(controller:'controller1',action:'action1')}", 
      data: "dataToSend="somedata, 
      success: function(data){//data is the message rendered from action1 
       window.location = ${createLink(controller:'controller2',action:'action2')} 
      }, 
      error: function(){ 
       alert("Error from controller 1 action 1"); 
      } 
     }); 

위해 jQuery를 사용하는 경우, 당신은 아약스 이벤트에 다시 렌더링해야합니다

class controller1 { 
    def action1 = { 
     ........ 
     some code/logic 
     ........ 
     def message = "some message, success! or error!" 
     render(text:message, type:,contentType:'text/xml') 
    } 
} 
4

당신은 컨트롤러 속성에 대한 올바른 컨트롤러 이름을 줄 필요가

redirect(controller:'controller2',action:'action2') 
관련 문제