I can't seem to make an ajax call to my Web API controller. Either the URL isn't right (method not found) or I get a method not allowed error. This is my ajax call:
$.ajax({
url: 'server/InstallApp',
type: 'POST',
data: {server: serverAsJson, appWithGroup: appWithGroupAsJson},
contentType: "application/json",
success: InstallRequested
});
That ajax call is being called from this URL:
http://serverName/PrestoWebApi/app/#/server/ApplicationServers%5E%5E8
These are the various URLs I've tried to use in the above ajax call, and the result:
url: 'server/InstallApp'
POST http://serverName/PrestoWebApi/app/server/InstallApp 404 (Not Found)
Notice that the # is missing. Not sure if that matters.
url: '#/server/InstallApp'
POST http://serverName/PrestoWebApi/app/ 405 (Method Not Allowed)
Not sure why the URL is truncated like that. Why Method Not Allowed when the URL doesn't even match the controller?
url: '/PrestoWebApi/app/#/server/InstallApp'
POST http://serverName/PrestoWebApi/app/ 405 (Method Not Allowed)
I'm not sure what to try. I've done this with other apps. I even tried putting webdav removal entries in my web.config.
This is my controller (note that I can call the Get method in my controller):
[EnableCors(origins: "http://serverName", headers: "*", methods: "*")]
public class ServerController : ApiController
{
public ApplicationServer Get(string id)
{
// Get code here
}
[HttpPost]
public void InstallApp(ApplicationServer server, ApplicationWithOverrideVariableGroup appWithGroup)
{
Debug.WriteLine("snuh");
}
I'm at a loss. Any ideas on what to try?