views:

63

answers:

3

When I use the following link in my browser, a record is populated in the form on this page to edit.

http://vcred.dev/#personal/myacademicdetail?record_id=15

When I click 'SAVE' button, record is successfully updated in database and form with updated values is still in front of me. It is OK for me. But I have only one problem after form is posted. In Address bar URL is still same as before post.

http://vcred.dev/#personal/myacademicdetail?record_id=15

But I want short URL without params in address bar after my form is posted like this:

http://vcred.dev/#personal/myacademicdetail

How it is possible using javascript?

A: 

I'd do it like this, using PHP:

$referer_host = $_SERVER[ "HTTP_HOST" ];
$referer_uri = explode( "?", $_SERVER[ "REQUEST_URI" ] );
$referer = $referer_host . $referer_uri[ 0 ];

I assumed you might want to see also PHP solution as you've mentioned zend-framework as one of your tags.

I'd simply explode URL like this and then use headers for redirect.

Ondrej Slinták
yes it is a way but I want to do it without reloading the page.
NAVEED
+1  A: 

Since you are using a hash in the URL, you could do the following in JavaScript:

location.href = location.protocol + "//" + 
                location.host + 
                location.pathname + 
                location.hash.split('?')[0];

This will not cause a page refresh, as described in this Stack Overflow post: How do I, with javascript, change the URL in the browser without loading the new page?

Daniel Vassallo
Yes it helped me but I have to edit your statement. location.href = location.protocol + "//" + location.host + '/#personal/myacademicdetail';
NAVEED
In fact I have just noticed that you had a hash (#) in your URL. You can use my modified answer to have it working without hard-coding the part after the hash.
Daniel Vassallo
yes. it is working perfectly now. thanks
NAVEED
Someone told me that "I'm sure the ? in hash will not work in ie6 and ie7"
NAVEED
A: 

As far as Zend Framework goes, after you save the record use:

$this->_redirect('#personal/myacademicdetail');

This will tell the user's browser to go to the URL.

smack0007