Мой вопрос: Node использует request.write для отправки JSON пост-запроса, а jquery 's AJAX использует поле' data '. Я правильно понимаю?
Вот мой node.js
const apiToken = "eae5819bd5e14803a1abff8141c36ee6";
const contentJSON = JSON.stringify({
'contestId': "0ac3ac99-0509-456a-8ff6-9f193048c4f3",
'contesttype': "OverUnder",
'direction': "moon",
'wager': "0.001"
});
const https = require('https');
const options = {
hostname: 'beta.hxro.io',
port: 443,
path: '/hxroapi/api/ContestEntry/add-contest-entry',
method: 'POST',
headers: {
'Content-Type':'application/json',
'Ocp-Apim-Subscription-Key': 'agh383j89dh93ij9',
}
}
const req = https.request(options, (res) => {
res.on('data', (d) => {
console.log(JSON.parse(d));
});
});
req.on('error', (error) => {
console.error(error);
});
req.write(contentJSON);
req.end();
Это то, что я думаю в jQuery это будет выглядеть так:
contentJSON = {
contestId: contestId,
userId: "AB",
contesttype: "OverUnder",
direction: "moon",
wager: "0.00005"
};
console.log(contentJSON);
$.ajax({
type: "POST",
url: "https://beta.hxro.io/hxroapi/api/ContestEntry/add-contest-entry",
data: JSON.stringify(contentJSON),
contentType: "application/json; charset=utf-8",
dataType: "json",
headers: {
"Content-Type": "application/json",
"Ocp-Apim-Subscription-Key": "sa77euhe83ji40ie"
},
success: function(data) {
console.log(data);
},
failure: function(errMsg) {
alert(errMsg);
}
});
Узел один работает, но не jquery. JS решения приветствуются.