• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2366
  • Last Modified:

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
0
gerrie-govaerts
Asked:
gerrie-govaerts
  • 3
  • 2
  • 2
1 Solution
 
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
 
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
leakim971PluritechnicianCommented:
>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
 
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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now