简体   繁体   中英

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.

$.post("/coupon/sync"/, .....)

Chrome develpment tools shows that the request url is localhost:8373/coupon/aync

But when I publish the website into server, which hosts like:

在此处输入图片说明

( pm is the website I published)

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.

Because PM is not a permanent web app name, it may changes to pm2 or something else. So I don't want to have the PM set in every ajax url property. Is there a soluthing?

put "~" sign before your path. check below snippet.

$.post("~/coupon/sync"/, .....)

Or

$.post("../coupon/sync"/, .....)

This will work for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM