Jump to content

AJAX change the url


hgmme@wa

Recommended Posts

I'm using ajax to change a pages content (duh) to be able to view a specific user, and I was wonder if it was possible to change what the user is seeing for a url as the page content changes? If it's not possible to do that, then what's take to have a "bookmark me" button that bookmarks the specific user they're viewing.

Link to comment
Share on other sites

There is one way it could be done: by adding a hash to the URL.For example: mydomain.com/file.htm#hashThen with a script you could do something like this:window.onload = function() {str = location.hashif(substr(1) != "") { //if the hash has a lengthopenPage(str);}}The function openPage() would be substituted for the name of the function you're using to load pages at the moment.You can't change the content of the navigation bar, so you'll have to change your links and make them like this;<a href="#category" onmouseup="openPage('category')">Text</a>

Link to comment
Share on other sites

I think you misinterpreted what I'm needing...?Let's use some examples this time like I knew I should have done to begin with.Ok so a user first go's to "http://www.example.com/userinfo.php".'>http://www.example.com/userinfo.php". Then that page loads and he/she uses a drop down box to select a user they want to view. The form uses ajax to display the user. Want I want to be able to do is when the user uses that drop down box and clicks a user then the user information appears, and I want at the same time that the user information appears what's visible for a url to go from "http://www.example.com/userinfo.php" to "http://www.example.com/userinfo.php?viewedID=1" even though they didn't actually change pages. But it appears I can't do that, so what's it take to create a button for bookmarking the link that will go to that specific user.

Link to comment
Share on other sites

Guest FirefoxRocks
I think you misinterpreted what I'm needing...?Let's use some examples this time like I knew I should have done to begin with.Ok so a user first go's to "http://www.example.com/userinfo.php".'>http://www.example.com/userinfo.php". Then that page loads and he/she uses a drop down box to select a user they want to view. The form uses ajax to display the user. Want I want to be able to do is when the user uses that drop down box and clicks a user then the user information appears, and I want at the same time that the user information appears what's visible for a url to go from "http://www.example.com/userinfo.php" to "http://www.example.com/userinfo.php?viewedID=1" even though they didn't actually change pages. But it appears I can't do that, so what's it take to create a button for bookmarking the link that will go to that specific user.
Have you tried using a PHP GET request to do that?
Link to comment
Share on other sites

I don't have a problem with getting the variable from the url! I want the what's visible for a url to change as I use ajax to change the page content, that way when a page viewer originaly goes to "http://localhost/userinfo.php" then uses the form that uses ajax to change some of the page content the url changes also so they can bookmark what they were looking at.

Link to comment
Share on other sites

well in the form use the get method and make some hidden inputs like this:<form method="get" action="example.com/url.html"><input type="text" name="something" /><input type="text" name="yaddayadda" /><input type="Submit" value="Submit" /></form>and then the url would come out like this: soemtingtsometing.php?something="Userinput"&yaddayadda="userinput"

Link to comment
Share on other sites

Ok I think Ingolme came closer to seeing what I need. I already have the form, and I already have the ajax that submits the form. I also already have the form processing stuff fixed up. But what I want is the seen url to change even though they haven't left the page. So that even though they're still at, "http://www.example.com/userinfo.php" the ajax has now made the page so that it's "http://www.example.com/userinfo.php?viewedID=4", but since I used ajax, they don't see that they went to the last url shown. But I don't think I can change the url, so what's it take to create a button that bookmarks the url I specify?

Link to comment
Share on other sites

Ok I think Ingolme came closer to seeing what I need. I already have the form, and I already have the ajax that submits the form. I also already have the form processing stuff fixed up. But what I want is the seen url to change even though they haven't left the page. So that even though they're still at, "http://www.example.com/userinfo.php" the ajax has now made the page so that it's "http://www.example.com/userinfo.php?viewedID=4", but since I used ajax, they don't see that they went to the last url shown. But I don't think I can change the url, so what's it take to create a button that bookmarks the url I specify?
read what i posted again.<form method="get" action="thewebsitetheformison"><input type="text" name="something" /><input type="text" name="yaddayadda" /><input type="Submit" value="Submit" /></form>
Link to comment
Share on other sites

I know what you posted. Your saying to submit the form the normal way, instead of with afax, which in this case isn't what I'm wanting to do...Now that I think I have the answer to my original question, I'd like to know how to make a "bookmark this page" button that bookmarks a page I specify.

Link to comment
Share on other sites

What you need to do is make a function that calls the AJAX request when it loads, and I recommended using a hash.The script I gave you should work for all AJAX requests you may want to make for the page. For example, for user IDs you could do something like this #ID52 and then send an AJAX request something like this:xmlHttp.send( "userID=" + location.hash.substr(3) );(And all the rest of the code as well)

Link to comment
Share on other sites

Sorry Ingolme, I just figured out what your saying to do, and realize that it could probably do what I want. But I'm not sure exactly how I would do it. I'm using a drop down box for the page viewer to select the person they want to view, so I don't know how I would go about sending them to that url. I think I'd rather create a book mark this page button instead though. So I'm going to research that, and if someone know a good tutorial on that, let me know. (or you could walk me through it) Thanks.

Link to comment
Share on other sites

I'm using a drop down box for the page viewer to select the person they want to view, so I don't know how I would go about sending them to that url.
What about something that uses the onchange event of the select? E.g.
<script type="text/javascript">function updateurl(ele) {location.hash = ele.value;}</script><!-- ... --><select onchange="updateurl(this)"><option>Your</option><option>Options</option></select>

read what i posted again.
Do you know what AJAX is? :)http://www.w3schools.com/ajax/
Link to comment
Share on other sites

That might work. Something that occurred to me last time I replied to this topic is that I hope to add some mod_rewrite magic to it, so that I can have the url look more like "www.example.com/userinfo/1". So I don't know if that creates a major kink in the hash idea?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...