user2412146
user2412146

Reputation: 103

Jquery all ajax calls not picking relative url - ASP.NET MVC

$(document).ready(function () {
    getDefaultPDF();
    loadPDF();   
});

function loadPDF() {
    $('#reportsDiv').load("/Review/DisplayPdfPartial");
}

Our site is hosted under the Default website, within a folder. So the url should be http://servername/foldername/Review/DisplayPdfPartial

but the following code tries to fetch http://servername/Review/DisplayPdfPartial - doesn't add the foldername and fails obviously.

This doesn't happen on local, only when deployed under default website.

What am I missing?

Upvotes: 0

Views: 140

Answers (2)

Tushar Gupta
Tushar Gupta

Reputation: 15923

You can use ResolveClientUrl

A fully qualified URL to the specified resource suitable for use on the browser.

Use the ResolveClientUrl method to return a URL string suitable for use by the client to access resources on the Web server, such as image files, links to additional pages, and so on

.

Upvotes: 1

Kartikeya Khosla
Kartikeya Khosla

Reputation: 18873

As you have mentioned you are using Asp.Net MVC then in that case instead of specifying url's this way, a more efficient way is to use @Url.Action() helper method as shown :-

$(document).ready(function () {
    getDefaultPDF();
    loadPDF();   
});

function loadPDF() {
    //$('#reportsDiv').load("/Review/DisplayPdfPartial");
    $('#reportsDiv').load('@Url.Action("DisplayPdfPartial","Review")');
}

Upvotes: 2

Related Questions