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

  • Home
  • SEARCH
  • 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 6010805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:10:08+00:00 2026-05-23T02:10:08+00:00

In my ASP.net web project, I’ve written the following Javascript code in a .js

  • 0

In my ASP.net web project, I’ve written the following Javascript code in a .js file:

function getDeviceTypes() {
    var deviceTypes;
    $.ajax({
        async: false,
        type: "POST",
        url: "Controls/ModelSelectorWebMethods.aspx/getDeviceTypes",
        data: '{ }',
        contentType: "application/json;",
        dataType: "json",
        success: function(response) {
            deviceTypes = response.d;
        },
        error: function(xhr, status) {
            debugger;
            alert('Error getting device types.');
        }
    });    // end - $.ajax
    return deviceTypes;
}

It was working great until I tried to load this .js file into a page in a subdirectory.

Let’s suppose that the name of my project is widget.

When I use this code in the main virtual directory, Javascript interprets Controls/ModelSelectorWebMethods.aspx/getDeviceTypes to mean https://mysite.com/widget/Controls/ModelSelectorWebMethods.aspx/getDeviceTypes and all is well. However, from the page in a subdirectory, Javascript interprets it to mean https://mysite.com/widget/subdirectory/Controls/ModelSelectorWebMethods.aspx/getDeviceTypes and it doesn’t work.

How can I write my Javascript code so that the AJAX web method can be called from pages in any directory in my application?

  • 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-05-23T02:10:09+00:00Added an answer on May 23, 2026 at 2:10 am

    You’ve got two options:

    1. Build a configuration/ preferences object in JavaScript which contains all your environment specific settings:

       var config = {
           base: <% /* however the hell you output stuff in ASPX */ %>,
           someOtherPref: 4
       };
      

      and then prefix the AJAX url with config.base (and change the value for config.base whether you’re on a dev/ testing/ deployment server.)

    2. Use the <base /> HTML tag to set the URL prefix for all relative URL’s. This affects all relative URL’s: image’s, links etc.

    Personally, I’d go for option 1. You’ll most likely find that config object coming in handy elsewhere.

    Obviously the config object will have to be included in a part of your site where server-side-code is evaluated; a .js file won’t cut it without configuring your server. I always include the config object in the HTML <head>; its a small config object, whose contents can change on each page, so it’s perfectly warrented to stick it in there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If you create an ASP.NET web file project you have direct access to the
I'm working on an ASP.NET Web Project with some AJAX magic. As my GridView
I have an ASP.net Web Site Project (.net 3.5). Currently all of the non-code
Below is my code (ASP.net web project), but when i debug this asp page
I'm using AJAX on an ASP.NET web project to update a page. Some of
I have a asp.net web project I am working on, and found out my
I working on a ASP.NET web project where Ajaxpro.2 is referenced, and it seems
I have an ASP.NET VB.NET web project that references a VB.NET class library. I
Our team is developing a rather big ASP.NET web project which initially started in
The Scenario I have an ASP.NET web project. I want to be able to

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.