前端使用config中設定值

Posted by Leo Yang on 2023-11-22
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//定義ajax設定
var settings =
{
"url": "http://xxx.xxx",
"method": "POST",
"timeout": 0,
"headers": {
"Content-Type": "application/json"
},
"data": JSON.stringify({
"IsinCode": parameterIsinCode,
"UserID": parameterUserID
}),
};

//呼叫API
$.ajax(settings).done(function (response)
{
response = jQuery.parseJSON(response);
if (response.ResponseCode == '0000')
{
alert('新增成功');
}
else
{
alert('新增失敗' + response.ResponseMessage);
}

});

在url那邊可以這樣寫

1
"url": "<%=$"{System.Configuration.ConfigurationManager.AppSettings["WsWebAPI"]}Observable/Add"%>",
1
"url": "http://xxx.xxx",