Accessing $_COOKIE immediately after setcookie()

前端 未结 9 1057
轻奢々
轻奢々 2020-11-22 05:43

I\'m trying to access a cookie\'s value (using $_COOKIE) immediately after calling the setcookie() function in PHP. When I do so, $_COOKIE[\

9条回答
  •  轮回少年
    2020-11-22 06:16

    We can do this using AJAX calling.

    If we want to create cookies on button click so first create a AJAX call for creating cookies then the success of first AJAX calling we can call another AJAX for getting the cookies.

        function saveCookie() {
                var base_url = $('#base_url').val();
                var url = base_url + '/index/cookie';
                $.ajax({
                    'url': url,
                    'type': 'POST',
                    'success': function (data) {
                        if (data) {
                            var url = base_url + '/index/get_cookie';
                            $.ajax({
                                'url': url,
                                'type': 'POST',
                                'success': function (response) {
                                    var container = $('#show');
                                    if (response) {
                                        container.html(response);
                                    }
                                }
                            });
                        }
                    }
                });
            }
    
        
        

提交回复
热议问题