我正在配置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);
}
});
答案 0 :(得分:0)
首先:
accountid
,你的jQuery有accountNumber
post
而非POST
Accept
并且在Content-Type