Reputation: 1016
I'm having trouble understand what my ajax call is doing. I have a partial view used in a few different pages that is called the same way.
function showChoice(divID) {
$.get('/Add/Examples/' + divID, function (data) {
$('#partialExamples').html(data);
});
}
This works fine on local host, but now I am trying to move this application over to a server, where the url will start with http://apps/test/
.
This test
part of the url is screwing up my ajax calls. All other routes leave the full url beginning and tack on the route to the end, for example http://apps/test/add
and others. But these ajax calls try to go to http://apps/add/examples
and completely get rid of the test
piece of the url.
I've tried add/examples
(so without the first slash) but this adds this url to the end of the current url instead of going back to the start url.
So if i'm on http://apps/test/review
and i call this function, it goes to https//:apps/add/examples
instead of https//:apps/test/add/examples
.
Any ideas?
SOLVED:
$.get('@Url.Action("PduExamples", "AddPdu", new { id = "_ID" })'.replace("_ID", divID)
Upvotes: 0
Views: 166
Reputation: 791
Yoy can use
<base href="YourOptionalRout" />
in html to modify relative ajax path
Upvotes: 0
Reputation: 6423
change
$.get('/Add/Examples/' + divID, function (data) {
to
$.get('@Url.Action("Examples", "Add")' + divID, function (data) {
Upvotes: 1