Lost Password?

Go Back   CodeCall Programming Forum > Web Development Forum > AJAX

AJAX Web based language that allows asynchronous loading of pages that does not interfere with normal page loading.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-19-2008, 04:46 PM
CygnetGames's Avatar   
CygnetGames CygnetGames is offline
Programmer
 
Join Date: May 2007
Location: York, England
Posts: 113
Rep Power: 5
CygnetGames is on a distinguished road
Default Change querystring with Javascript

I'm making an ajax search page. I've got all the ajax working, but there's a usability issue with the query string.

In my setup, the user types a search query and clicks a button. Then javascript fetches the results via ajax and injects them into the page. All good.

The problem is - I want the user to be able to bookmark their search, or email the url to a friend, etc. With a naive way of doing ajax, they won't be able to do this as the url of the page doesn't change when a search is made.

So what I want to be able to do is to alter the query string of the url using javascript without reloading the page. Is this possible?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 03-20-2008, 07:13 AM
fahlyn's Avatar   
fahlyn fahlyn is offline
Learning Programmer
 
Join Date: Nov 2007
Age: 25
Posts: 35
Rep Power: 3
fahlyn is on a distinguished road
Send a message via ICQ to fahlyn Send a message via AIM to fahlyn Send a message via MSN to fahlyn Send a message via Yahoo to fahlyn
Default Re: Change querystring with Javascript

I don't believe that is possible. I don't think you'd want to save the actual URL you're using for your ajax request anyway....would you? Wouldn't that either be XML, JSON or just an HTML snippet, and not your entire page? Why don't you add an optional argument to your page....like http://www.domain.com/search/?crit=s...teriaHere...or something....then have a link or button that says Bookmark these results or send these results to a friend...and send them the link above so you load your entire page, and not just the results from your ajax call. Just change searchCriteriaHere each time they do a different search.

Does that make sense?
__________________
Visit My Google Group Here: Web Development Innovation
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-21-2008, 11:18 AM
CygnetGames's Avatar   
CygnetGames CygnetGames is offline
Programmer
 
Join Date: May 2007
Location: York, England
Posts: 113
Rep Power: 5
CygnetGames is on a distinguished road
Default Re: Change querystring with Javascript

Thanks for the reply.
I've got half of what you are saying already. I have a parameter so that if someone visits the url http://www.domain.com/search/?crit=searchCriteria, then the search will be performed.
What I want is, if they visit the url http://www.domain.com/search/, enter their criteria and click on the button, the url will change to http://www.domain.com/search/?crit=searchCriteria but the page will not reload. The search will be performed using ajax.

Anything I've tried with javascript (like assigning to document.location.search) makes the page reload, which is what I don't want to happen.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-21-2008, 06:03 PM
fahlyn's Avatar   
fahlyn fahlyn is offline
Learning Programmer
 
Join Date: Nov 2007
Age: 25
Posts: 35
Rep Power: 3
fahlyn is on a distinguished road
Send a message via ICQ to fahlyn Send a message via AIM to fahlyn Send a message via MSN to fahlyn Send a message via Yahoo to fahlyn
Default Re: Change querystring with Javascript

When you change document.location the browser is going to navigate to that URL. You could create a text box for the "Search Location" that has the URL you want so the user can copy it...other than that...unless you want the page to refresh, i think you're out of luck.
__________________
Visit My Google Group Here: Web Development Innovation
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-22-2008, 10:30 AM
CygnetGames's Avatar   
CygnetGames CygnetGames is offline
Programmer
 
Join Date: May 2007
Location: York, England
Posts: 113
Rep Power: 5
CygnetGames is on a distinguished road
Default Re: Change querystring with Javascript

I've come up with a solution now.
I'm using (not sure what it's called, but...) the part of the url after the # character.
So instead of visiting http://www.domain.com/search/?crit=searchCriteria, the user visits http://www.domain.com/search/#crit=searchCriteria.
Javascript can change document.location without the page reloading if only the part after the # has been changed. Then I use javascript to parse the "query string" after the # and do the relevant ajax.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 03-22-2008, 02:00 PM
fahlyn's Avatar   
fahlyn fahlyn is offline
Learning Programmer
 
Join Date: Nov 2007
Age: 25
Posts: 35
Rep Power: 3
fahlyn is on a distinguished road
Send a message via ICQ to fahlyn Send a message via AIM to fahlyn Send a message via MSN to fahlyn Send a message via Yahoo to fahlyn
Default Re: Change querystring with Javascript

Interesting. I believe that's called an anchor link. Usually, that is used to link from one section of an HTML document to another via the "name" attribute of the "a" tag.

Good deal, I'm glad you were able to figure something out. So do you have some on page load event that triggers to parse the query string and do your Ajax search?

One thing that you may consider depending on your site's traffic is efficiency. When a user clicks the link with the anchor link info in it for your ajax search you will hit the server and do the work for the initial page load, then your javascript will automatically hit the server again to perform your search. Just something you may want to keep in mind that each one of those page loads will result in (a minimum of) 2 round trips.
__________________
Visit My Google Group Here: Web Development Innovation
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 03-23-2008, 05:08 AM
CygnetGames's Avatar   
CygnetGames CygnetGames is offline
Programmer
 
Join Date: May 2007
Location: York, England
Posts: 113
Rep Power: 5
CygnetGames is on a distinguished road
Default Re: Change querystring with Javascript

Quote:
Originally Posted by fahlyn View Post
Interesting. I believe that's called an anchor link.
Cheers - I was wondering what it was called.

Quote:
Originally Posted by fahlyn View Post
Just something you may want to keep in mind that each one of those page loads will result in (a minimum of) 2 round trips.
Yeah, that's not a worry for my application though.
The main reason for using the ajax is to make sure that the rest of the page is loaded before the search is initiated.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Nortan Popup Blocker + JavaScript Issue twalters84 JavaScript and CSS 3 03-11-2008 04:47 AM
PHP accessing through remotely javascript from another website deny Request Services (Paid) 4 01-28-2008 08:02 AM
[Easy as Pie] Unobtrusive JavaScript Kernel Programming News 0 12-20-2007 09:07 AM
Using change management Cosmet General Programming 2 10-30-2006 06:16 PM
Change design to make more $ Montecarlo Website Design 11 07-13-2006 12:05 PM


All times are GMT -5. The time now is 10:27 AM.

Contest Stats

Xav ........ 164.00000
dargueta ........ 128.00000
John ........ 127.00000
gaylo565 ........ 18.00000
XaNaX ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

Ads