How to use Server.MapPath in jQuery JavaScript when deploying on Hosting Server
I am using WebMethod
on my ASPXpage and I call it from jQuery on the same page like this:
$.ajax({
type: "POST",
url: "Mypage.aspx/GetSomeData",
contentType: "application/json; charset=utf-8",
data: parameters,
dataType: "json",
success: AjaxSucceeded,
error: AjaxFailed
});
This works fine in my debug environment, but when I deploy on the hosting site it does not.
The problem seems to be in the URL because on the server the path would be different. So I used Server.MapPath
in various ways but none of them worked.
E.g
url: '<%= Server.Map开发者_Go百科Path("MyPage.aspx/GetSomeData")%>',
When I use the above code snippet it does not work on my machine. MyPage
is in the root directory.
You probably just need a tilde to start at the root of the app:
url: '<%= Server.MapPath("~/MyPage.aspx/GetSomeData")%>'
EDIT
Try using:
<%= ResolveUrl("~/MyPage.aspx") %>
精彩评论