Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.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_Mysql_Ajax_Codeigniter_Modal Dialog - Fatal编程技术网

如何在php中使用ajax在模式中检索配置文件数据?

如何在php中使用ajax在模式中检索配置文件数据?,php,mysql,ajax,codeigniter,modal-dialog,Php,Mysql,Ajax,Codeigniter,Modal Dialog,这里的交易,我已经创建了一个搜索结果页面,我想打开一个模式,并通过php中的ajax检索配置文件数据,但我不太确定如何实现它。我已经创建了模式,但我不知道如何通过单击搜索结果获取“id”,并将其传递到ajax以检索概要文件细节 推特有这种功能;当您单击提要中的用户名时,它会打开一个模式,并为您提供简要的概要信息,以及指向完整概要信息的链接 如果有人能帮我走出困境或给我指出正确的方向,这对我来说意义重大!:) 另外,我正在使用codeigniter,如果有人想知道我在使用什么框架的话 编辑:这是代

这里的交易,我已经创建了一个搜索结果页面,我想打开一个模式,并通过php中的ajax检索配置文件数据,但我不太确定如何实现它。我已经创建了模式,但我不知道如何通过单击搜索结果获取“id”,并将其传递到ajax以检索概要文件细节

推特有这种功能;当您单击提要中的用户名时,它会打开一个模式,并为您提供简要的概要信息,以及指向完整概要信息的链接

如果有人能帮我走出困境或给我指出正确的方向,这对我来说意义重大!:)

另外,我正在使用codeigniter,如果有人想知道我在使用什么框架的话

编辑:这是代码

<?php
/*** PHP Search Results Loop ***/
if ($num > 0){
foreach ($query->result_array() as $row)
{
    echo "link to ajax"'>";
}
} else {
echo "<strong>results not found :(</strong>";
}?>


<script> /* jQuery Runs When Result Has Been Clicked */
    $('#ResultText').click(function() {

        var targetid = {
            id: /*Profile Id*/,
            ajax: '1'
        };

        /* Modal Code */
        $('.modal-backdrop, .modal-profilebox').css('display', 'block');
        $('.modal-backdrop').animate({'opacity':'.50'}, 100, 'linear');
        $('.modal-profilebox').animate({'opacity':'1.00'}, 200, 'linear');

        $.ajax({
            url: "<?php echo site_url('finder/modal'); ?>",
            type: 'POST',
            data: form_data,
            success: function(profileData) {
                $('.modal-profilebox').html(profileData);
            }
        });

        return false;
    });
</script>

试试这样的方法

public function ajax_user_profile($user_id)
{
    if( !$this->input->is_ajax_request() )
    {
        redirect('/'); //only allow ajax requests
    }

    try
    {
        $user_profile = ''; //grab user object from DB

        if( !$user_profile )
            throw new Exception("Error Message");
    }
    catch(Exception $e)
    {
        log_message('error', $e->getMessage());
        echo json_encode(array(
            'error' =>  1
        ));
        exit;
    }

    $data = $this->load->view(array(
        'some_view' =>  'some_view',
        'user'      =>  $user_profile
    ), TRUE); //NO Template, just the view by adding TRUE

    echo json_encode(array(
        'error' =>  0,
        'data'  =>  $data
    )); //return view data

}
--


如果您提供了一些您正在使用的代码,特别是搜索结果、ajax和modal codehey,我可以帮助您!谢谢你的回复!只是看看,它看起来很有希望!我会试一试,让你知道结果如何:)
<a rel="modal" data-user-id="1" >Joe Bloggs</a>
(function($){

    var userObj = {

        init : function(){
            this.getProfile();
        },
        getProfile : function(){

            var modalSearch = $("a[rel='modal']");

            modalSearch.on('click', function(){

                //trigger the modal window

                //request ajax
                $.ajax({
                    url : BASEPATH + 'users/profile/' + $(this).data('user-id'),
                    type : 'POST',
                    dataType: 'json',
                    success : function(callback){
                        if(callback.error ==0)
                        {
                            $('.modal-profilebox').html(callback.data);
                        }
                    }
                });
            });

        }
    }

    $(function(){
        userObj.init()
    });
})(jQuery);