How to remove params from URL after form is submitted?
When I use the following link in my b开发者_JS百科rowser, 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?
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?
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.
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.
精彩评论