呼叫API时AJAX邮政请求编辑



我正在配置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);
}
});

启动器:

  1. 您的卷发具有accountid,您的jQuery具有accountNumber
  2. 您的HTTP方法是post,而不是POST
  3. 您的jQuery标题缺少Accept,并且Content-Type中的空格很奇怪

最新更新