gpt4 book ai didi

c# - 在 Visual Studio C# 中,有没有办法将 Web Config 转换应用于 Javascript 文件?

转载 作者:搜寻专家 更新时间:2023-11-01 04:19:23 26 4
gpt4 key购买 nike

在 Visual Studio 中,我正在开发的网站上有一些 Javascript 代码。在调试时,我正在使用 $ajax 调用“localhost”。部署时,它需要是实际的服务器:

$('#textInput_UserName').focusout(function () {
var _username = $('#textInput_UserName').val();
$.ajax({
url: 'http://localhost:8809/Account/UserNameExists/',
data: { username: _username },
dataType: 'html',
});

当我发布时,我需要将该本地主机转换为实际域:

$('#textInput_UserName').focusout(function () {
var _username = $('#textInput_UserName').val();
$.ajax({
url: 'http://www.mydomain.com/Account/UserNameExists/',
data: { username: _username },
dataType: 'html',
});

是否有一种简单/自动的方法来执行此操作,类似于 Web Config 转换的工作方式?

非常感谢!

最佳答案

你不需要,你只是省略了主机,浏览器会为你填写这个,就像这样:

$('#textInput_UserName').focusout(function () {
var _username = $('#textInput_UserName').val();
$.ajax({
url: '/Account/UserNameExists/',
data: { username: _username },
dataType: 'html',
});

如果您实际上是在谈论 x 域请求,我怀疑您是,那么只需设置一个全局 js 站点变量。

关于c# - 在 Visual Studio C# 中,有没有办法将 Web Config 转换应用于 Javascript 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10916952/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com