0

I'm trying to do a jQuery Ajax call to a URL that has a # sign in it. For example:

https://www.foo.com/myapp/app/#ptc1/tcomp/infoPage?oid=VR:wt.doc.WTDocument:1272991906

However, the URL being called by the Ajax call is being truncated to just "https://www.foo.com/myapp/app/". It appears as this is because jQuery treats the # sign as an anchor designator and strips everything after it off of the URL.

So, I tried using both encodeUriComponent and doing a straight up replace to convert the # sign to it's hex equivilent of %23. However, if I do that and call the URL, I then get a 404.

Is there any way around this or is the fault on the server for not understanding that %23 is the same as #?

UPDATE

Maybe I should re-phrase this question, as it is not getting any answers.

Is there any way to tell JQuery to NOT strip off everything after the # sign in a URL for an Ajax call?

Zendog74
  • 65
  • 2
  • 13
  • Why do you need the hash exactly? Do you get the value of the hash on the server side? The hash is usually used to demark navigation within a single page application and is usually not used on the server-side so it could be stripped from the url, can't you just set the hash after doing the ajax? – Eduardo Wada Apr 20 '15 at 17:16
  • No, unfortunately the hash is required. It is part of the server's architecture I am guessing. It is not just used to denote in page navigation. If I load the base part of the URL before the hash, it just takes me to a main page of the application. – Zendog74 Apr 20 '15 at 17:21
  • I created a fiddle so that everyone can see what happens when trying to use encodeUriComponent and manually escaping the # signs: http://jsfiddle.net/fdmyw3Lp/1/ – Zendog74 Apr 20 '15 at 19:16

1 Answers1

0

It appears as this is because jQuery treats the # sign as an anchor designator and strips everything after it off of the URL.

That isn't jQuery, that's the browser.

Fragment identifiers are never sent to the server as part of the URL.


The URL you've provided throws a 404 error (presumably you were trying to provide an example URL, please use example.com for that, foo.com is a real site!) but I would assume that anything shown on the page which changes based on what comes after the # is put there by client side JavaScript in the page, and not by the server.

In order to replicate it, you would need to reverse engineer their JS and reproduce the changes it makes to the page in your own code.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335