jquery - Javascript in Virtual Directory unaware of Virtual Directory -
Say I have a virtual virtual directory where
I have an Ajax request that is defined In a javascript file using JQuery,
$ GetJSON ("/ controller / verb")
When it is called, the customer tries to find the URL at the original level
If I were to tilde (~ ), It turns into
(if it was supposed to be done that I should have done it)
Any ideas about fixing this?
I used this solution successfully
Put the following elements in your master page < / P>
& lt;% = Html.Hidden ("HiddenCurrentUrl", Url.Action ("dummy"))% & gt;
Announce a global variable in your main JavaScript file
var baseUrl = "";
When your Javascript is loaded, set the base URL based on the "Hild Content URL"
baseUrl = $ ("# HiddenCurrentUrl "). Val (); BaseUrl = baseUrl.substring (0, baseUrl.indexOf ("dummy"));
Use baseUrl
$. GetJSON (baseUrl + "verb")
Edit Better Solution
In your Controller
ViewBag.BaseUrl = Request.Url.GetLeftPart (UriPartial.Authority) + Requests. Application Form + "/";
In your master page
& lt; Script type = "text / javascript" & gt; Var YourNameSpace = YourNameSpace || {}; YourNameSpace.config = {baseUrl: "@ ViewBag.BaseUrl"} & lt; / Script & gt;
Use your baseUrl
$ GetJSON (YourNameSpace.config.baseUrl + "Action")
Comments
Post a Comment