Click here to Skip to main content
15,567,415 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I have developed an MVC 4 application and used AJAX to call controller action. Locally its working fine but when I published and deployed it on local server, it gives me error and failed to call controller action from AJAX.

I have tried to find out the solution& came across about URL passed in AJAX method. I made it as

url: '@Url.Action("Method_Name", "Controller_Name")',

but still it is giving error. Can anybody help me regarding this, what the mistake I am doing here?


Thanks in advance!


XML
ERROR:

Failed to load data..{"readyState":4,"responseText":"<!DOCTYPE html>\r\n<html>\r\n <head>\r\n <title>The resource cannot be found.</title>\r\n <meta name=\"viewport\" content=\"width=device-width\" />\r\n <style>\r\n body {font-family:\"Verdana\";font-weight:normal;font-size: .7em;color:black;} \r\n p {font-family:\"Verdana\";font-weight:normal;color:black;margin-top: -5px}\r\n b {font-family:\"Verdana\";font-weight:bold;color:black;margin-top: -5px}\r\n H1 { font-family:\"Verdana\";font-weight:normal;font-size:18pt;color:red }\r\n H2 { font-family:\"Verdana\";font-weight:normal;font-size:14pt;color:maroon }\r\n pre {font-family:\"Consolas\",\"Lucida Console\",Monospace;font-size:11pt;margin:0;padding:0.5em;line-height:14pt}\r\n .marker {font-weight: bold; color: black;text-decoration: none;}\r\n .version {color: gray;}\r\n .error {margin-bottom: 10px;}\r\n .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }\r\n @media screen and (max-width: 639px) {\r\n pre { width: 440px; overflow: auto; white-space: pre-wrap; word-wrap: break-word; }\r\n }\r\n @media screen and (max-width: 479px) {\r\n pre { width: 280px; }\r\n }\r\n </style>\r\n </head>\r\n\r\n <body bgcolor=\"white\">\r\n\r\n <span><H1>Server Error in '/keepslip' Application.<hr width=100% size=1 color=silver>...eUnknownAction(String actionName)\r\n at System.Web.Mvc.Controller.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult)\r\n at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar)\r\n at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()\r\n at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)\r\n at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar)\r\n at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()\r\n at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)\r\n at System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult)\r\n at System.Web.Mvc.MvcHandler.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult)\r\n at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar)\r\n at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()\r\n at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)\r\n at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)\r\n at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()\r\n at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)\r\n-->","status":404,"statusText":"Not Found"}
Posted
Comments
thatraja 2-May-14 10:53am    
Check the "Routes", global.asax
Sanket Saxena 2-May-14 11:10am    
Post your ajax call and the controller method

Look at the end of the error. You got a HTTP 404 - Not Found error. In other words, the Method Name and Controller Name you specified are wrong.
 
Share this answer
 
Hi all,

Many thanks to all of you for your nice reply and giving your time.

I could fixed it, actually the problem was I have used "~" symbol in src. I replaced it with "../" and it started to work fine.


Thanks once again to you.
 
Share this answer
 
v2
Comments
Member 12415621 27-Jan-17 5:41am    
Super yaar..it worked for me..thank you
Navin Pandit 27-Jan-17 9:52am    
Thank you!

You can find more stuffs at http://navinpandit.blogspot.in/
Member 12270013 19-Feb-19 10:43am    
well I am new to MVC and unable figure out, which 'src' you made change in? I encountered this recently.
Please help!
Navin Pandit 21-Jul-19 10:43am    
Oops! Sorry I saw your comment late and I hope you fixed it now.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900