Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

jQuery / javascript Resolve client URL

Posted on 2010-09-21
7
Medium Priority
?
2,327 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
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:Gurvinder Pal Singh
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 82

Accepted Solution

by:
leakim971 earned 750 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 …
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

636 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