I'm sending data to the server using JSON and post method, but I can't read the response from the server. Here's my code:
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://staging.smartenupcs.com/api/v1/licenses/create", true);
xhr.setRequestHeader("Smartenup-API-KEY", "webflow.c407d56c5ab23115af0075+DzDMrMtWZENCoct9Pa7DUA54mIgP8c9o");
var jsonStr = JSON.stringify({
"first_name": "Bla",
"last_name": "Blabla",
"email": "[email protected]",
"product_name": "webflow_essentials",
"order_id": 21811,
"voucher": null
});
xhr.send(jsonStr);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
var myObj = JSON.parse(xhr.responseText);
alert(myObj);
}
};
I tried many options but no success.
I hope someone can help, thank you in advance
