亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

PHP 遍歷 cookie 數組

PHP 遍歷 cookie 數組

PHP
斯蒂芬大帝 2021-08-28 18:38:18
在我的 cakephp 應用程序中,我試圖創建一個評論功能。所以我使用 ajax 請求來獲取評論,然后克隆一個 html 模板并將其附加到頁面://load comments    $(document).ready(function(){        $.ajax({                type: 'POST',                url: '/app/tasks/getComments',                datatype: 'json',                beforeSend: function (xhr) { // Add this line                           xhr.setRequestHeader('X-CSRF-Token', $('[name="_csrfToken"]').val());                        },                data: {                        task_id : "<?php echo $task->id; ?>"                },                success: function( data )                {                    for (var i=0; i < data.length; i++)                    {                        //Clone the template                        var item = $(template).clone();                        document.cookie = 'photos['+i+']='+data[i].user.photo;                        document.cookie = 'names['+i+']='+data[i].user.username;                        //Find the  element                        $(item).find('#comment_photo').html('<?php if(isset($_COOKIE["photos[$num]"])) {echo $this->Html->image($_COOKIE["photos[$num]"], ["class" => "avatar avatar-online", "alt" => $currentUser->username]); }  ?>');                        $(item).find('#comment_username').html('<?php if(isset($_COOKIE["names[$num]"])) { echo $_COOKIE["names[$num]"]; }?>');                        $(item).find('#comment_time').html(moment(data[i].created_date, 'DD-MM-YYYY hh:mm:ss').format('MMMM Do YYYY, h:mm:ss a'));                        $(item).find('#comment_text').html(data[i].comment);                        $(item).find('#comment_id').html(data[i].id);                        //Append to the source                        $('#target').append(item);                    }                }            });    });為了在 php 中訪問返回的結果,我將它們存儲在 cookie 數組 ( photos[], names[]) 中。我如何設置和更新 的值$num以便在每個 html 代碼附加中迭代數組?用這種方法可以實現我想要的嗎?或者我需要一個全新的?
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 267 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號