jQuery / javascript Resolve client URL

Hello

In my jQuery script I want to load content using the $.post method.
In this method I point to a specific controller etc...
Instead of using the fixed path localhost/StockManamgent ...... I would like jQuery to be able to resolve the used url for the virtual directory in IIS.

$.post("http://localhost/StockManagement/Stock/LoadBrands/" + materialId, null, function (data)


Is this possible?

Thx
gerrie-govaertsAsked:
Who is Participating?
 
leakim971Connect With a Mentor PluritechnicianCommented:
>Instead of using the fixed path localhost/StockManamgent ...... I would like jQuery to be able to resolve the used url for the virtual directory in IIS.
>Is this possible?
Not with Javascript

You may use something like : var vdir = "<%= Server.MapPath("\\LoadBrands").Replace("\\","\\\\") %>"

http://www.w3schools.com/ASP/met_mappath.asp

Test page :

(create a new website named WebSite123)
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <script language="javascript" type="text/javascript">
        var vdir = "<%= Server.MapPath("\\WebSite123").Replace("\\","\\\\") %>";
        alert(vdir);
    </script>
</head>
<body>
    <form id="form1" runat="server">
    </form>
</body>
</html>

Open in new window

0
 
Gurvinder Pal SinghCommented:
you can see the current URL using
location.href;
http://www.w3schools.com/jsref/prop_loc_href.asp

let me know if i missed something
0
 
gerrie-govaertsAuthor Commented:
No I'm sorry I can't get enough information from the location object.

Here are the possible options: http://www.javascriptkit.com/jsref/location.shtml

I actually need the virtual directory of IIS, not the controller, action etc...

0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Gurvinder Pal SinghCommented:
If the virtual directory is there in current URL, you can get it from location.href,
else you need to send it from the server side script.
0
 
leakim971PluritechnicianCommented:
Did you tried the two dots : ../

For example : ../../../otherDirectory/blabla
0
 
gerrie-govaertsAuthor Commented:
var virtualPath = "<%=HttpRuntime.AppDomainAppVirtualPath%>";

solved my problem, so thx for giving me a good hint !

Gerrie
0
 
leakim971PluritechnicianCommented:
You're very welcome! Thanks for the points Gerrie!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.