Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 重定向页面时如何将ajax后的数据带到控制器_Php_Jquery - Fatal编程技术网

Php 重定向页面时如何将ajax后的数据带到控制器

Php 重定向页面时如何将ajax后的数据带到控制器,php,jquery,Php,Jquery,如何将ajax post数据带到控制器重定向页面时,我已从获得id\u用户数据,但当重定向数据页面为空/0时,我如何通过控制器将post ajax数据带到重定向页面,请帮助我,如果不清楚,请道歉并询问我 注意:我使用PHP原生MVC 这是我的密码 $(document).ready(function(){ $('.edit').on('click', function(){ var id_user =$(this).attr("id_user"); alert(i

如何将ajax post数据带到控制器重定向页面时,我已从
获得id\u用户数据,但当重定向数据页面为空/0时,我如何通过控制器将post ajax数据带到重定向页面,请帮助我,如果不清楚,请道歉并询问我

注意:我使用PHP原生MVC

这是我的密码

$(document).ready(function(){
$('.edit').on('click', function(){
        var id_user =$(this).attr("id_user");
        alert(id_user);
        var url =$(this).attr("href");
        $.ajax({
            type:'post',
            url: url,
            data:{id_user:id_user},
            success: function(data){
                alert(data)
            },
            error:function(err){
                alert(err)
            }
        });
    });
});
<a class="edit" href="<?php echo BASE_URL. "app.php/usermanagement/edit "?>" id_user="<?php echo $row ['idx'] ?>">Edit</a>
这是我的控制器

public function edit(){

        Template::setTitle('Edit User Management');

        $id_user = (int)Request::post('id_user');

        $result = $this->getUserbyId($id_user);      

        $dataresult = json_decode($result, true);
        if($dataresult === NULL) {
            echo "<script language = \"javascript\">window.alert(\No Have Data\");";
            echo "javascript:history.back();</script>";
            return false;
        }
        $data = $dataresult;
        return $data;
公共函数编辑(){
模板::setTitle(“编辑用户管理”);
$id_user=(int)请求::post('id_user');
$result=$this->getUserbyId($id\u user);
$dataresult=json_decode($result,true);
如果($dataresult==NULL){
echo“window.alert(\No Have Data\”);
echo“javascript:history.back();”;
返回false;
}
$data=$dataresult;
返回$data;
这是我的密码

$(document).ready(function(){
$('.edit').on('click', function(){
        var id_user =$(this).attr("id_user");
        alert(id_user);
        var url =$(this).attr("href");
        $.ajax({
            type:'post',
            url: url,
            data:{id_user:id_user},
            success: function(data){
                alert(data)
            },
            error:function(err){
                alert(err)
            }
        });
    });
});
<a class="edit" href="<?php echo BASE_URL. "app.php/usermanagement/edit "?>" id_user="<?php echo $row ['idx'] ?>">Edit</a>

这是我的问题

我已获取数据id\u用户,我已发送数据使用警报

但当我重定向页面时,这就是结果

当我重定向页面时,我想得到这样的数据

这是我添加“防止默认值”时的新错误

因为您有一个行列表,并且以某种方式呈现它们,所以您可以为每个实体分配记录的
id

<a class="edit" href="<?php echo BASE_URL. "app.php/usermanagement/edit_user?id_user=" . $row['idx']; ?>">Edit</a>
您的JQuery代码应该如下所示:

public function edit_user(){

  if(isset($_GET['id_user'])){

    //TODO: make something with it
    var_dump($id_user);
    die();
  } else {
    //throw an error 
  }
}
$('.edit').on('click', function(){
        var id_user =$(this).attr("id_user");
        alert(id_user);
        var url =$(this).attr("href");
        $.ajax({
            type:'post',
            url: url,
            data:{id_user:id_user},
            success: function(data){
                //alert(data);
                window.location = '/app.php/usermanagement/edit_user?id_user=' + id_user;
            },
            error:function(err){
                alert(err);
            }
        });
    });

使用
Session
存储临时数据,或者使用get参数重定向并在控制器中检查它们。我想我给了你一个在重定向时如何获取数据的方法。链接不是重定向,除非你使用一些Javascript,否则不能通过post发送变量。我想bes的方法是在URL中包含用户id,但你需要告诉我们如何你是否构建链接以从URL获取值。你能告诉我们如何安排代码吗?@Serghei Leonenco首先我从
获取数据,然后我使用jquery捕获id_用户数据,我通过id_用户警报了解到了这一点,然后在我获取id_用户数据后,我将数据传递给控制器,使其成为可以使用的变量d调用curl-rest服务,只要流可以帮助我吗?@Triby我已经在两周内死锁以解决此问题您的链接错误,应该是这样的:is-Parse error:syntax error,意外的T\u-ENCAPSED\u和\u-WHITESPACE,在
中期待T\u字符串或T\u变量或T\u NUM\u字符串我已经做了我所给出的,但是show“不明“@Serghei LeonencoWhat
undentified
?它在哪里显示此错误?在什么点上?是的..在这一点上,我没有获得数据id\u用户..@Serghei Leonencoi编写url就像你给我答案一样,当我再次编写url就像在我问你之前一样,我添加了默认值(),但我得到了数据,我的页面edit_user.php显示警报,你的意见如何,我将在上面显示我的截图。@Serghei Leonenco