【发布时间】:2021-10-09 15:01:13
【问题描述】:
在 JavaScript ajax API 调用中处理实时和开发主机 URL 的最佳方法是什么?
例如,如果开发主机是https://hostdev.com/do-something,而直播是https://hostlive.com/do-something,我如何让它知道要使用哪个主机?
$.ajax({
type: 'post',
url: 'https://hostdev.com/do-something',
dataType: "json",
data: data,
contentType: 'application/json',
context: this,
success: function (data) {
...
},
error: function (result) {
...
});
【问题讨论】:
-
你可以在布局中设置一个全局变量来定义host的值,然后在你所有的ajax方法中,将url设置为variable+"/do-something"。
标签: javascript asp.net ajax asp.net-core