2016-03-24 40 views
0

我想打一個postJelix腳本:如何使用post的成功函數的數據參數?

{literal} 
<script type="text/javascript"> 

    $(function(){ 

     $("#btnCalculerNote").on("click",function(){ 
      iIdUser = $("#id_user").val() ; 
      $.post(
       "{/literal}{jurl 'default:calculerNote', array()}{literal}", 
       {"id_utilisateur": iIdUser}, 
       function(data) 
       { 
        alert ("Calcul des notes terminé") ; 
        // here I want to get the returned url inside the data param 
       } 
      ); 

     }); 
    }); 
</script> 
{/literal} 

裏面的「默認」控制器:

function calculerNote() 
{ 
    $rep = $this->getResponse ("redirect"); 
    ... 
    $rep->action = "default:index"; // default is name of the controller , index is the name of the action inside the default controller 
    return $rep ; 
} 

正如你可以看到我想要的頁面重定向到「默認:指數「網址。那麼如何讓它在$.post的功能裏面呢?

+0

從重定向的控制器post方法..只是發回一些json令牌值回ajax調用,然後使用'location.href = ...'在ajax回調內重定向。 –

+0

那麼應該由json返回的值是什麼? – pheromix

+0

雖然我不熟悉php,但可能是您可以返回您想要重定向爲json對象的url,然後在ajax成功回調中使用它來重定向。 –

回答

0

我不知道你的條件

爲什麼不嘗試你這樣

function calculerNote() 
{ 
    $rep = $this->getResponse ("redirect"); 
    ... 
    return json_encode(['action' => 'default:index'] ; 
} 

而且在爵士成功的功能,您可以改用這樣

window.location.herf = data.action; 
相關問題