Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/445.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
Javascript Yii2在按钮上单击pass id以使用ajax渲染部分_Javascript_Jquery_Ajax_Yii2 - Fatal编程技术网

Javascript Yii2在按钮上单击pass id以使用ajax渲染部分

Javascript Yii2在按钮上单击pass id以使用ajax渲染部分,javascript,jquery,ajax,yii2,Javascript,Jquery,Ajax,Yii2,因此,在我的索引页面上,我列出了我的模型中的所有行和一些字段,单击按钮,我希望弹出一个模式,其中包含按钮对应行中的所有数据 因此,单击按钮我希望ajax调用呈现局部视图,这将要求我在执行ajax调用时传递项目的id <div class="col-sm-3 small-item"> <div class="inner-wrapper"> <img src="<?=

因此,在我的索引页面上,我列出了我的模型中的所有行和一些字段,单击按钮,我希望弹出一个模式,其中包含按钮对应行中的所有数据

因此,单击按钮我希望ajax调用呈现局部视图,这将要求我在执行ajax调用时传递项目的id

            <div class="col-sm-3 small-item">
                <div class="inner-wrapper">
                    <img src="<?= $model->featured_img; ?>" class="img-responsive"/>
                    <div class="overlay">
                        <h4><?= $model->title; ?></h4>
                        <p><?= $model->sub_title; ?></p>
                        <a data-toggle="modal" data-target="#modal" class="btnsolid-sm btn-black">View Full Data</a> //this is the button that when clicked the popup should appear with all the related data
                    </div>
                </div>
            </div>
$.ajax({
    url: 'my/url/bla',
    data: {
        id: record_id
    },
    success: function() {
        // magic here 
    } 
});

特色图片;?>“class=”img responsive“/>

查看完整数据//单击此按钮时,弹出窗口应显示所有相关数据
为什么不在保存记录id的按钮上添加另一个属性。比如说
数据id=“”

因此,当您单击JS中的按钮时,可以使用

var record_id = $(this).data('id');
然后将其用作ajax调用的数据

            <div class="col-sm-3 small-item">
                <div class="inner-wrapper">
                    <img src="<?= $model->featured_img; ?>" class="img-responsive"/>
                    <div class="overlay">
                        <h4><?= $model->title; ?></h4>
                        <p><?= $model->sub_title; ?></p>
                        <a data-toggle="modal" data-target="#modal" class="btnsolid-sm btn-black">View Full Data</a> //this is the button that when clicked the popup should appear with all the related data
                    </div>
                </div>
            </div>
$.ajax({
    url: 'my/url/bla',
    data: {
        id: record_id
    },
    success: function() {
        // magic here 
    } 
});