JQuery ajax call returns 404

This code works fine when it is running locally (IISExpress). But it fails when I deploy it to the dev server.

It is confirmed that the controller is not hit when I make this call.

I have spend a lot of time to work on but still cannot figure it out. Really appreciate for any help. Big Thanks in advance

[GET] http://mydomain.net/Server/SetServerStatus?serverId=2&isActive=false 
404 (Not Found)

        function SetServerStatus(serverId, isActive) {
            var actionUrl = '/Server/SetServerStatus?serverId=' + serverId + '&isActive=' + isActive
                url: actionUrl,
                type: 'GET',
                dataType: "JSON",
                success: function (data) {
                    var x = data;

                error: function (xhr, ajaxOptions, error) {



        public ActionResult SetServerStatus(int serverId, bool isActive)
            log.Info("\nCall SetServerStatus.  ServerId=" + serverId.ToString());

            Server note = _serverService.GetByID(serverId);
            note.ServerStatus = isActive ? (int)ServerStatus.Active : (int)ServerStatus.Inactive;

            ServerListItem noteViewModel = Mapper.Map<ServerListItem>(note);
            return Json(new { result = "success" }, JsonRequestBehavior.AllowGet);
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
What if you set URL to the full path to the server instead of a relative path - does it work?
chuang4630Author Commented:
Just tried. It works. But why?

I did not use the explicit path in the other projects and they all worked well. Wondering what is missing or not configured right
Julian HansenCommented:
There are many things that could be the cause - for instance if you are using URL re-writing you may not have set this up correctly in the new environment - or your environment's are different so httpd.ini on IIS needs to be .htaccess on linux or vice versa.
You might be operating out of a sub folder so if your site is


Then /Server will refer to the root folder and not some_folder

You need to look at how your two environments are configured to see what is causing the routing problem.
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

chuang4630Author Commented:
You are right. Folder is the reason.

Some of the JS code are part of chtml. So how do I specify a global variable from the configration, or dynamically detect it?
Julian HansenCommented:
a quick and dirty is to add a <base> tag to your head

<base href="http://path_to_root_folder" />

I prefer to use absolute paths
I would imagine in your case the following links are relevant

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chuang4630Author Commented:
It works if you make ajax call to the same controller. But if you make ajax call to the different controller, it does not work.

<base href="http://brcesdev.risk.regn.net/OrbitHealthMonitor/" target="_blank"/>
var actionUrl2 = '/Server/SetServerStatus?serverId=1&isActive=true'

The "/" before the Server ignores the folder "OrbitHealthMonitor" and take it directly to the root.
If you Use "Server/Set.....", then relative path respects the folder "OrbitHealthMonitor", but it limit to the same controller. If you call the different controller, then you have to use the absolute path. That will cause the problem (for code maintenance)
chuang4630Author Commented:
I end up using global var.

        window.globalVar = getRoot();

        function getRoot() {
            var url = document.URL.replace("/Index","");
            var pos = url.lastIndexOf("/");
            var siteRoot = url.substring(0, pos);
            return siteRoot;

var actionUrl = window.globalVar + '/Notification/SetJobStatus?notificationId=' + notificationId + '&isActive=' + isActive
Julian HansenCommented:
Can I take from your last post that it is now working?
chuang4630Author Commented:
Excellent answer!
Julian HansenCommented:
Thank you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.