【发布时间】:2021-12-21 07:20:32
【问题描述】:
我在 StartUp.cs 中编写了以下用于调用我的 API 的代码。
services.AddHttpClient("MyApi", c =>
{
#if DEBUG
c.BaseAddress = new Uri("https://localhost:12345");
#else
c.BaseAddress = new Uri("https://myApi.com");
#endif
但是当我想通过Ajax-call调用ActionResult时,他找不到API。
alert(apiUrl);
$.ajax({
url: apiUrl + '/MyApiProcesses/GetSomething',
type: 'POST',
所以我把这个变量写在了一个 js 文件中。
var apiUrl = 'https://localhost:12345';
//var apiUrl = 'https://myApi.com';
我想知道是否可以动态编写。如果在启动时声明,就不用声明两次了吗?
【问题讨论】:
标签: javascript c# ajax api model-view-controller