1

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?

Naveed
  • 38,915
  • 31
  • 92
  • 129

3 Answers3

1

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?

Community
  • 1
  • 1
Daniel Vassallo
  • 312,534
  • 70
  • 486
  • 432
  • Yes it helped me but I have to edit your statement. location.href = location.protocol + "//" + location.host + '/#personal/myacademicdetail'; – Naveed Feb 01 '10 at 11:51
  • 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 Feb 01 '10 at 11:54
  • Someone told me that "I'm sure the ? in hash will not work in ie6 and ie7" – Naveed Feb 01 '10 at 12:48
1

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
  • 10,165
  • 7
  • 38
  • 46
0

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
  • 29,278
  • 20
  • 90
  • 124