简体   繁体   English

jQuery发布并在本地Intranet和实时服务器上获取不同的请求

[英]jquery post and get request different on local intranet and live server

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. 我一直在开发一个asp.net mvc应用程序,在该应用程序中,我需要进行大量的jquery发布并获取调用控制器方法的请求并获取json结果。 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. 问题是我不得不写不同的jquery帖子,并在本地Intranet(通过制作虚拟目录部署)和实时服务器上获取请求url。

the current jquery request url is given as below: 当前的jquery请求网址如下:

$.post("/ProjectsChat/GetMessages", { roomId: 24 },.......... $ .post(“ / ProjectsChat / GetMessages”,{roomId:24},..........

now this format of url for jquery request works fine for live server but not for local intranet. 现在,这种用于jquery请求的url格式对实时服务器有效,但不适用于本地Intranet。 Since on local intranet i have made a virtual directory. 由于在本地Intranet上,我已经创建了一个虚拟目录。 It only works when i append the name of the virtual directory like this "$.post("MyProjectVirutalDirName/ProjectsChat..................." 仅当我附加虚拟目录的名称时才起作用,例如“ $ .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. 现在我已经完成了一个完整的项目,有大量的jquery请求,我想通过在本地Intranet上部署来测试应用程序并修复错误。 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. 更改对本地Intranet的所有jquery请求对我来说似乎不是可行的解决方案,我确实遇到了很大的问题,我无法像这样那样在实时服务器上部署相同的项目并对其进行测试,客户端会杀死我。

I need some expert advice. 我需要一些专家意见。

Please help 请帮忙

Thanks 谢谢

To avoid this problem, and many similars I have setup and run locally iis5.1 为避免此问题,我已经在本地安装了iis5.1并在其中运行了许多类似版本

I suggest to make the same for not so small projects. 我建议对于不那么小的项目也要这样做。 You can make your development better and faster because you do not need to run the visual studio on debug mode every time to see whats change, you just see your pages on browser, and programming on visual studio. 您可以使开发更快更好,因为您不需要每次都在调试模式下运行Visual Studio来查看更改,只需在浏览器上查看页面,并在Visual Studio上编程即可。

If you need to debug a part of your code, you can do attach to process, or just drop this line of code and your program start the debugging Debug.Assert(false); 如果您需要调试部分代码,则可以将其附加到进程中,或者只是删除此行代码,然后程序将开始调试Debug.Assert(false);。

Hope this help. 希望能有所帮助。

I would suggest you to avoid hardcoding urls in your javascript. 我建议您避免在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: 在视图内定义一个全局javascript变量,该变量将保存该地址,并将使用html helper计算该变量:

var messagesAddress = '<%= Url.RouteUrl(new { controller = "ProjectsChat", action = "GetMessages" }) %>';

And then use this variable inside your script: 然后在脚本中使用此变量:

$.post(messagesAddress, { roomId: 24 },..........

Use a base tag in your master page header and change it as required... 在母版页眉中使用基本标签,并根据需要进行更改...

<base href="http://site/MyProjectVirutalDirName"></base>

this is a quick fix and means you dont have to go through all of your code 这是一个快速修复,这意味着您不必遍历所有代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM