jquery post 和 get 请求在本地 Intranet 和实时服务器上不同

发布于 2024-08-30 03:45:33 字数 687 浏览 2 评论 0原文

我一直在开发一个 asp.net mvc 应用程序,我需要进行大量的 jquery post 和 get 请求来调用控制器方法并获取 json 结果。一切正常。

问题是我必须编写不同的 jquery post 并在本地 Intranet(通过创建虚拟目录部署)和实时服务器上获取请求 url。

当前的 jquery 请求 url 如下:

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

现在这种格式的 url jquery 请求适用于实时服务器,但不适用于本地 Intranet。因为在本地 Intranet 上,我创建了一个虚拟目录,它仅在我附加虚拟目录的名称时才有效,如“$.post(”MyProjectVirutalDirName/ProjectsChat)。 ..................."

我相信你们中的大多数人一定遇到过同样的问题。

现在我已经做了一个完整的项目,有大量的发出 jquery 请求,我想通过在本地 Intranet 上部署来测试应用程序并修复错误,更改本地 Intranet 的所有 jquery 请求对我来说似乎不是可行的解决方案,我确实遇到了一个大问题,我无法部署。在实时服务器上进行相同的项目并在那里进行测试,客户端会杀了我,

我需要一些专家的建议,

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

优雅的叶子 2024-09-06 03:45:33

我建议你避免在 JavaScript 中硬编码 url。您遇到的问题是原因之一,另一个原因是您决定改变路线。您可以这样做。在视图中定义一个全局 JavaScript 变量来保存地址,并将使用 html 帮助程序计算该地址:

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

然后在脚本中使用此变量:

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

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:

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

And then use this variable inside your script:

$.post(messagesAddress, { roomId: 24 },..........
荒芜了季节 2024-09-06 03:45:33

为了避免这个问题,以及许多类似的问题,我在本地设置并运行了 iis5.1

我建议对不太小的项目进行相同的操作。您可以使您的开发更好更快,因为您不需要每次都在调试模式下运行 Visual Studio 来查看发生了什么变化,您只需在浏览器上看到页面,并在 Visual Studio 上进行编程。

如果您需要调试代码的一部分,您可以附加到进程,或者只需删除这行代码,您的程序就开始调试 Debug.Assert(false);

希望这有帮助。

To avoid this problem, and many similars I have setup and run locally 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.

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);

Hope this help.

野の 2024-09-06 03:45:33

在母版页标题中使用基本标记并根据需要更改它...

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

这是一个快速修复,意味着您不必遍历所有代码

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文