[英]AJAX url not found because the web server is hosted as an sub app of another website on IIS
I need to send an AJAX request, and the program is ok when I run it at my pc. 我需要发送一个AJAX请求,并且在我的PC上运行该程序时,程序正常。
$.post("/coupon/sync"/, .....)
Chrome develpment tools shows that the request url is localhost:8373/coupon/aync
Chrome开发工具显示请求网址为
localhost:8373/coupon/aync
But when I publish the website into server, which hosts like: 但是,当我将网站发布到服务器时,其主机如下:
( pm is the website I published) ( pm是我发布的网站)
The correct request url should be www.xxx.com/pm/coupon/aync
, but the actual url is www.xxx.com/coupon/aync
(/pm is missing), so the server returns me a 404 not found error. 正确的请求网址应为
www.xxx.com/pm/coupon/aync
,但实际的网址为www.xxx.com/coupon/aync
丢失),因此服务器向我返回404 not found错误。
Because PM is not a permanent web app name, it may changes to pm2 or something else. 由于PM不是永久的Web应用程序名称,因此它可能会更改为pm2或其他名称。 So I don't want to have the PM set in every ajax url property.
所以我不想在每个ajax url属性中都设置PM 。 Is there a soluthing?
有没有解决办法?
put "~" sign before your path. 在您的路径前加“〜”号。 check below snippet.
检查以下代码段。
$.post("~/coupon/sync"/, .....)
Or 要么
$.post("../coupon/sync"/, .....)
This will work for you. 这将为您工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.