0

I have a page that I am working on that is mainly asynchronous. I want to append a variable at the end of my url when the user clicks a row.
Ie.
1. URL: asr-web-dev1:8881/?s=101-01
2. user clicks on a row
3. URL: asr-web-dev1:8881/?s=101-01&id=153474

EDIT: I don't know how to do this. My code that I have does not work. The page is in PHP.

Here is my 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

                }
            });*/
        });

Thank you for your help! :)

maryjane
  • 171
  • 2
  • 10
  • I'm thinking an equals sign after the id in the concatenated URL would be the issue but this could be checked with Firebug, Fiddler or other inspection tools. – JB King Nov 24 '14 at 21:17

2 Answers2

0

I'm not 100% sure what you're asking but I have some possible solutions.

Do you want the user to click the row and then the URL of the current page to change without reloading?

Modify the URL without reloading the page

Or do you want the URL of the clicked row to change before redirecting to that page?

So, user click the tr element, it changes the href attribute of that element, and then goes to that URL?

Try this

$('#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');
});
Community
  • 1
  • 1
Owen Kavanagh
  • 187
  • 1
  • 11
  • I'm trying to populate another part of the page when a user clicks the row with information from that row. Kind of redundant I know but it's what they want. That other part allows changes to certain information and allows a change of address update in a separate form. – maryjane Nov 24 '14 at 21:36
  • Owen, I think maybe the page could refresh on this with the added variable. Would the code above achieve this? I tried plugging it into my page and it did nothing :( – maryjane Nov 24 '14 at 21:47
  • If you're trying to change the `href` attribute of another element (i.e. not the clicked `tr`) then you need to change the line, in your original code, where you alter the `href` attribute of `$(this)` to `$('a#element_you_want_to_change')` The reason is because when you clicked the `tr` element and use `$(this)` in your code it's trying to change the `href` attribute of the clicked table row. – Owen Kavanagh Nov 25 '14 at 15:51
0

is not this what you missed????

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

after you commented i thibk you need session variables of php.

$_SESSSION['id'] = $_GET['id'];
moroccan_dev
  • 310
  • 1
  • 2
  • 11
  • No considering the numbers after the "s=" is going to change constantly depending on what the user enters into the search box. – maryjane Nov 24 '14 at 21:39
  • Needs to take the current URL and append the id. – maryjane Nov 24 '14 at 21:40
  • are you trying to GET from the current page? – moroccan_dev Nov 24 '14 at 21:45
  • I was changing the current address before AJAXing when i still was a hacker – moroccan_dev Nov 24 '14 at 21:50
  • Ok so I have a table filled with addresses and I want to get the id of the row the user clicked and then based off of that id populate some fields on the same page but I dont want to lose the serach information. So I figure I could just add the variable to the url and then use a get to do the ajax calls to and from the database when updating/changing information if that makes sense? – maryjane Nov 24 '14 at 22:14
  • the s= is whatever the user entered to search so i thought just add the id= whatever to the end of that url. The page can refresh if the s= whatever is still in the url. I don't know what would be easiest, this is all new to me. :( – maryjane Nov 24 '14 at 22:15