将其他变量附加到 URL 的末尾


Append additional variable to the end of a URL

我有一个我正在处理的页面,主要是异步的。我想在用户单击行时在我的 url 末尾附加一个变量。
即。
1. 网址: asr-web-dev1:8881/?s=101-01
2. 用户点击一行
3. 网址: asr-web-dev1:8881/?s=101-01&id=153474

编辑:我不知道该怎么做。我拥有的代码不起作用。该页面是 PHP 格式的。

这是我的jQuery:

            $('#searchTable tr').click(function(){
            var parcel_id = $(this).attr('id');
            $(this).attr('href', window.location.href + '&id' + parcel_id);
            /*$.ajax({
                url: "classes/get-apn.php",
                //timeout: 30000,
                type: "GET",
                data: { 'parcel_id': parcel_id },
                dataType: 'json',
                error: function(SMLHttpRequest, textStatus, errorThrown){
                    alert("An error has occurred making the request: " + errorThrown)
                },
                success: function(data){
                    //do stuff here on success
                }
            });*/
        });

谢谢你的帮助! :)

我不是 100% 确定你在问什么,但我有一些可能的解决方案。

是否希望用户在不重新加载的情况下单击该行,然后单击当前页面的 URL?

修改网址而不重新加载页面

还是您希望在重定向到该页面之前更改单击的行的 URL?

那么,用户单击 tr 元素,它会更改该元素的 href 属性,然后转到该 URL?

试试这个

$('#searchTable tr').click(function(e){
        e.preventDefault();
        var parcel_id = $(this).attr('id');
        $(this).attr('href', window.location.href + '&id' + parcel_id);
        window.location = $(this).attr('href');
});
这不是

你错过的吗????

url: "classes/get-apn.php?s=101-01&id="+$(this).attr('id'),

在您评论我之后,您需要 PHP 的会话变量。

$_SESSSION['id'] = $_GET['id'];