1

I have 3 environments - development, stage and prod. I rely on jQuery for some ajax display. So I have something like that in my development:

   function needsForcedReset() {
           $.get("http://dev/_layouts/Ajax/DoesUserNeedForceResetPassword.aspx", function(result) {

        alert('got the data from force password ajax page: ' + result);

        if (result.toString().length > 0) {                
            showAlert('Your have to change your domain password now', 0, 
                false, false, notificationClass.fail);

            return true;
        }
        return false;
    });
    return false;

   }

So the point of interest is the hardcoded link inside the $.get function. How do I code with jQuery to make that link relative to the path of _layouts/ajax or code in the way that I dont have to specify the host for the url for each different deploy scenario?

2 Answers 2

3

Just drop the http://dev/ and use a server-relative url.

Sign up to request clarification or add additional context in comments.

Comments

0

There's multiple ways to do this. Here's two:

  1. Get the current document location through JS with window.location.href (for the full URL) or window.location.host (for the hostname + port). There's more variations of these, Google it.

  2. Set a html <base href="site.com" /> tag in the head section through your serverside programming logic (usually available in a constant for many CMS's or frameworks) and then extract it with jQuery: $('base') ... more info here: http://www.w3schools.com/TAGS/tag_base.asp

Cheers :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.