从php中获取url的值

i have passed a value through my url by using javascript, and i tried to access that variable in another page by using php $_POST but it is not working

<a data-room-type-id="<?php echo $rooms->id; ?>" class="btn-book-now" href=""><?php echo $rooms->name; ?></a>

I want to transfer the value data-room-type-id, below showing the javascript used for transfer value

tjq('.room-list').on('click', '.btn-book-now', function(e) {
        e.preventDefault();
        if (acc_data.booking_url) { alert(acc_data.booking_url);
            //var room_type_id = tjq(this).data('room-type-id');
            
            var roomid = tjq(this).data('room-type-id');
            alert("roomid = "+roomid);
            
            var room_type_id = '79';
            alert(room_type_id);
            
            tjq('input[name="action"]').remove();
            //booking_data = tjq("#check_availability_form").serialize();
            
            booking_data = 'accommodation_id=45&_wpnonce=32da73f035&date_from=10%2F26%2F2016&date_to=10%2F28%2F2016&rooms=1&adults=1&kids=0&child_ages%5B%5D=0';
            alert(booking_data);
            
            var form = tjq('<form method="get" action="' + acc_data.booking_url + '"></form>');
            form.append('<input type="hidden" name="booking_data" value="' + booking_data + '&room_type_id=' + room_type_id + '&roomid=' + roomid + '">');
            /*if ( acc_data.lang ) {
                form.append('<input type="hidden" name="lang" value="' + acc_data.lang + '">');
            }*/
            tjq("body").append(form);
            form.submit();
        } else {
            alert(acc_data.msg_no_booking_page);
        }
        return false;
    });

and javascript used in the code is above.

but in another page i can't retrieve the value roomid

the url is look this

http://www.medhyaftravel.com/accommodation-booking/?booking_data=accommodation_id%3D45%26_wpnonce%3D32da73f035%26date_from%3D10%252F26%252F2016%26date_to%3D10%252F28%252F2016%26rooms%3D1%26adults%3D1%26kids%3D0%26child_ages%255B%255D%3D0%26room_type_id%3D79%26roomid%3D59903

</div>
dongyuan1160
dongyuan1160 我用上面的网址更新了我的问题
接近 4 年之前 回复
douchi7073
douchi7073 你的网址是这样的页面.php?id=4?
接近 4 年之前 回复
dongzhabo2796
dongzhabo2796 它通常在PHP中由$_GET完成
接近 4 年之前 回复
dqczgtem06898
dqczgtem06898 检查$_SERVER
接近 4 年之前 回复

2个回答

your form is empty remove the ending form tag from var form and at the end after the hidden variables add this as below:

var form = tjq('<form method="get" action="' + acc_data.booking_url + '">');
        form.append('<input type="hidden" name="booking_data" value="' + booking_data + '&room_type_id=' + room_type_id + '&roomid=' + roomid + '">');
        form.append('</form>');
duan62819774
duan62819774 我的网址是传递变量,上面我用url修改了我的问题,我有了房间和一个值。 但我无法访问另一页中的变量
接近 4 年之前 回复

Your form uses method="get" so $_POST is empty. You will only get POST data if the form method is post. For GET request the data will be in $_GET. Please read up online on when to use get and when to use post, this is very important

$_GET['booking_data'] will contain the full booking data string.

This is probebly not what you what. You are adding a get url data to a formfield which the encodes it again.

You either add the get url data directly to the acc_data.booking_url used as action. Or create hidden form fields for each entry:

form.append('<input type="hidden" name="room_type_id" value="' + room_type_id + '">');
form.append('<input type="hidden" name="roomid" value="' + roomid + '">');

And so on for all values

dongpiaozhao6836
dongpiaozhao6836 不,我没有对上面显示的结果使用你的建议。
接近 4 年之前 回复
dqypcghd381390
dqypcghd381390 你对我的建议做了什么吗? 你是如何在php中读取数据的?
接近 4 年之前 回复
duanhongxian6982
duanhongxian6982 请查看我分享的网址,从中我可以检索所有其他数据,但只有我无法阅读的那个房间。
接近 4 年之前 回复
droe9376
droe9376 你需要更具体。 你改变了什么? 你能读什么,什么不读?
接近 4 年之前 回复
dounabi6295
dounabi6295 我也使用了$ _REQUEST,但我无法读取数据,但我也可以访问其他两个变量数据,只有这个我不能
接近 4 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐