admin管理员组文章数量:1429953
i belive it is quite simple question.
I am making an ajax call with jquery and all that i want is to set custom hash after the call similar to this:
window.location.hash = '?url=';
but it returns # symbol before that and i dont want it
www.mysitename/#?url=
so basically how to remove that # symbol and attach a clean hash without it?
Thank you.
i belive it is quite simple question.
I am making an ajax call with jquery and all that i want is to set custom hash after the call similar to this:
window.location.hash = '?url=http://www.sitename.';
but it returns # symbol before that and i dont want it
www.mysitename./#?url=http://www.sitename.
so basically how to remove that # symbol and attach a clean hash without it?
Thank you.
Share Improve this question asked Jan 31, 2011 at 23:32 devjs11devjs11 1,9588 gold badges43 silver badges73 bronze badges 2- 1 You want to set the hash without a hash? That is not possible. The hash is part of the hash, hence the word hash (actually it is the fragment identifier, but no one seems to care). (too much hashes here...) – Felix Kling Commented Jan 31, 2011 at 23:39
- as long as there are only too many hashes but not too much hashish.. ;) – ThiefMaster Commented Jan 31, 2011 at 23:46
2 Answers
Reset to default 6You cannot. If you want to set a query string (the ?something=something
stuff) you have to set it (and by doing so cause a page reload) by changing location.search
(only the query string) or location.href
- nothing AJAXish/Web2.0ish ;)
The hash is the client-side part after the #
sign and never sent to the server. It's purely meant to target page elements (for example a <h2 id="something">
is targeted by the hash #something
) and nowadays to keep state information in the URL so the back/forward buttons keep working in AJAX applications (even though that'll eventually be replaced with HTML5's pushState function).
If you still want to use the hash, please do so in a google-patible way. Basically it means you should use #!something
in the hash where something
could also be part of the real URL in a classical (non-AJAX) request.
The hash
in a URL is, per the MDC docs:
the part of the URL that follows the # symbol, including the # symbol.
Note that the #
character (which I believe is called the "pound sign" in North America) is generally called the "hash".
You want to set window.location.search
instead. This is:
the part of the URL that follows the ? symbol, including the ? symbol.
Note that this triggers a reload. If you don't want this, you need to use the hash
property.
本文标签: phpSet windowlocationhash on ajax callStack Overflow
版权声明:本文标题:php - Set window.location.hash on ajax call - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745536623a2662301.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论