javascript - MVC AJAX call url format -


I am working on a small MVC 5 application that contains some ideas and javascript files.

The project structure is very standard, i.e. normal layout for controllers, views, scripts etc., but I am having problems with AJAX calls while deploying to client system - where the application is deployed in the virtual directory It is, e.g. http: // host / application / .

The jquery AJAX call URL parameter does not resolve the problem continuously, for example, is happy with a script:

  $. Ajax ({url: 'Admin / Action' ....});  

while another requires

  $ Ajax ({url: '../controller/action' ....});  

and most recent one is required

  $ Ajax ({url: '../action' ....});  

I do not know whether I have done something different for these scripts (or controllers or ideas), so are the URLs being generated differently?

I can now work for this, but want to understand the cause of the problem, so I did not make any mistake later.

I recommend that you generate URLs for your Javascript server side (can change them if you Applications are hosted in IIS as a sub-app or some similar way) T4MVC is a very useful tool to add it through Nugget Check it

You can just save T4 and This will form strongly typed tasks (and lots of clean stuff too)

Or you can extend a studio extension, it is automatically called for you

What do you do again, create javascript objects in the razor and generate all the urls Are there. So if you change your controllers or actions, then you will compile time errors.

  var myUrls = {get: '@ Url.Action (MVC.MyController.Get ())', add: '@ Url.Action (MVC.MyController.Add ())'}  

Then use it like this:

  $ Ajax ({url: myUrls.get});  

and all your URLs are resolving problems =)


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -