Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7972159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:47:39+00:00 2026-06-04T07:47:39+00:00

I need some solution to give relative path in my jquery ajax call as

  • 0

I need some solution to give relative path in my jquery ajax call as of now I am using soem thing like ../ . Any suggestions would be higly appreaciated.

Code

$.ajax({
        type: 'get',
        url: '../../MyPage/getDetails',
        success: function (data) {
            if (data > 0) {
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:47:40+00:00Added an answer on June 4, 2026 at 7:47 am

    This is a bit of a hack, but you are client side so 🙂

    This code makes some assumptions – like that the script tage for myscript.js exists

    Assume you have some markup on your page like so:\

    <script src='../js/myscript.js' type="text/javascript"></script>
    <div>hiya</div>
    

    OK, now we will use the script tag and get the base url from that 🙂

    Let’s create a Util class we can use, add a get base url method and alert that value:

    Working copy here: http://jsfiddle.net/SmCLy/

    function Util() { /*...Nothing...*/
    }
    
    Util.getBaseURL = function() {
        //<summary>
        //    Returns the application base URL (well, a URL that is
        //    equivalent to such - it may have some "backtracking", 
        //    i.e. "../" at
        //    the end of the URL to simulate the root...)
        //</summary>    
        // 1) Find the script include for this JavaScript file:
        var scriptElements = document.getElementsByTagName("script"),
            getScriptPathFragmentPosition = Util.getBaseURL._getScriptPathFragmentPosition,
            getScriptPathFragmentPositionResult = getScriptPathFragmentPosition(scriptElements, "js/myscript.js"),
            posScriptPathFragment = getScriptPathFragmentPositionResult.posScriptPathFragment;
    
        // 2) Create the "base" URL by taking the current URL,
        // stripping the page from the end, and appending
        // sufficient "../" sequences to
        // construct the equivalent of the application's root URL:
        var scriptElementSrcLower = getScriptPathFragmentPositionResult.scriptElementSrcLower;
        var backPathToRoot = ((scriptElementSrcLower !== "") ? scriptElementSrcLower.substring(0, posScriptPathFragment) : "");
        var currentPath = location.href;
        var currentPathWithoutPage;
        var PAGE_TOKEN = ".aspx";
        var posPageToken = currentPath.toLowerCase().indexOf(PAGE_TOKEN);
        if (posPageToken > -1) {
            var trimmedPath = currentPath.substring(0, posPageToken + PAGE_TOKEN.length);
            currentPathWithoutPage = trimmedPath.substring(0, trimmedPath.lastIndexOf("/") + 1);
        } else {
            currentPathWithoutPage = currentPath.substring(0, currentPath.lastIndexOf("/") + 1);
        }
        return (currentPathWithoutPage + backPathToRoot);
    };
    
    Util.getBaseURL._getScriptPathFragmentPosition = function(scriptElements, scriptPathFragment) {
        var scriptElementsIndex = (scriptElements.length - 1),
            scriptElementSrc = "",
            scriptElementSrcLower = "",
            posScriptPathFragment = -1;
    
        while (scriptElementsIndex >= 0) {
            scriptElementSrc = scriptElements[scriptElementsIndex].getAttribute("src");
            if (typeof(scriptElementSrc) != "undefined" && scriptElementSrc !== null && scriptElementSrc !== "") {
                scriptElementSrcLower = scriptElementSrc.toLowerCase();
                posScriptPathFragment = scriptElementSrcLower.indexOf(scriptPathFragment);
    
                if (posScriptPathFragment >= 0) {
                    break;
                }
            }
    
            scriptElementsIndex--;
        }
    
        var result = {
            posScriptPathFragment: posScriptPathFragment,
            scriptElementSrcLower: scriptElementSrcLower
        };
    
        return result;
    };
    
    alert(Util.getBaseURL());
    

    SO, on your page you could do:

    var myajaxUrl = getBaseURL()+"MyPage/GetDetails";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This doesn't need to be a real time solution, but are there some log
I`m using Redmine for work in my company and I need some solutions (plugins)
Need some guidance figuring out what went wrong. I've been using mysql, phpmyadmin for
I'm new in Android development and I need some help coming with a solution
I have some strings(paragraphs) coming from DB. I need to give each of the
I'm using Prism so I can create a modular solution. I need to access
I need some information about localization. I am using .net 2.0 with C# 2.0
I need to execute some periodic console applications that give me some results (on
We need to implement some general-purpose object structure, much like an object in dynamic
Need some help, please. I have a line of horizontal thumbnails loaded as ONE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.