Solved

jQuery / javascript Resolve client URL

Posted on 2010-09-21
7
2,180 Views
Last Modified: 2013-11-08
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
Comment
Question by:gerrie-govaerts
  • 3
  • 2
  • 2
7 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33723548
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
 

Author Comment

by:gerrie-govaerts
ID: 33723594
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
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33723616
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 82

Accepted Solution

by:
leakim971 earned 250 total points
ID: 33724658
>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
 
LVL 82

Expert Comment

by:leakim971
ID: 33726032
Did you tried the two dots : ../

For example : ../../../otherDirectory/blabla
0
 

Author Closing Comment

by:gerrie-govaerts
ID: 33732439
var virtualPath = "<%=HttpRuntime.AppDomainAppVirtualPath%>";

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

Gerrie
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33733103
You're very welcome! Thanks for the points Gerrie!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
The viewer will learn how to dynamically set the form action using jQuery.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now