如何使用帖子成功函数的数据参数


How to work with the data parameter of the success function of a post?

我想将post转换为Jelix脚本:

{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 ;
 }

正如你所看到的,我想将页面重定向到"default:index"url。那么,如何将其纳入$.post的函数中呢?

我不确定你的条件

你为什么不试试这个

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

在js成功函数中,你可以像这样使用

window.location.herf = data.action;