I have been developing an asp.net mvc application where i need to make large amounts of jquery post and get request to call controller methods and get back json result. Everything is working fine.
The problem is i had to write different jquery post and get request url on local intranet(deployed by making virtual directory) and live server.
the current jquery request url is given as below:
$.post(“/ProjectsChat/GetMessages”, { roomId: 24 },……….
now this format of url for jquery request works fine for live server but not for local intranet. Since on local intranet i have made a virtual directory. It only works when i append the name of the virtual directory like this “$.post(“MyProjectVirutalDirName/ProjectsChat……………….”
I am sure most of you must have come across same problem.
now i have made a full project, there are large number of jquery requests made, i want to test the application by deploying on local intranet and fix the bugs. Changing all the jquery requests for local intranet doesn’t seem feasible solution to me, i am really in a big problem, i can’t deploy the same project on live server just like that and test it there, client will kill me.
I need some expert advice.
Please help
Thanks
I would suggest you to avoid hardcoding urls in your javascript. The problems you are encountering is one of the reasons, the other is if you decide to change your routes. Here’s what you could do instead. Define a global javascript variable inside the view that will hold the address and it will be calculated using html helpers:
And then use this variable inside your script: