jQuery Ajax Call on URL with Pound (Number) Sign

杀马特。学长 韩版系。学妹 提交于 2019-12-25 03:32:49

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/29753914/jquery-ajax-call-on-url-with-pound-number-sign

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!