我正在配置AJAX POST请求以击中API。
以下是curl命令(其虚拟):
curl -X POST
--header 'Content-Type: application/json'
--header 'Accept: application/json'
--header 'Authorization: token'
--header 'timestamp: test'
--header 'sourceSystemId: test'
--header 'sourceSystemUserId: test'
--header 'sourceServerId: test'
--header 'trackingId: test'
-d '{"accountid": "123456789","modeofBusiness": "Audio"}'
'https://services-services.c1.com:443/api/customer/v1/services/querySummary'
需要对此进行改革以使用Ajax请求进行击中。AJAX代码是什么?如何在此传递--header
和-d
标签?此API以JSON格式返回响应。以下是Ajax代码。
var accntno = document.getElementById('accntnoText').value;
var token = document.getElementById('tokenText').value;
//event.preventDefault();
var queryapi = "https://services-services.c1.com:443/api/customer/v1/services/querySummary";
$.ajax({
url: queryapi,
method: 'post',
dataType: "json",
data: { accountid: accntno, modeofBusiness: "Audio"},
headers: { 'Authorization': token,'timestamp': 'test', 'sourceSystemId':'test','sourceSystemUserId': 'test', 'sourceServerId':'test','trackingId': 'test','Content-Type':'application/json'},
success: function (data) {
alert(data);
}
});
启动器:
- 您的卷发具有
accountid
,您的jQuery具有accountNumber
- 您的HTTP方法是
post
,而不是POST
- 您的jQuery标题缺少
Accept
,并且Content-Type
中的空格很奇怪