Я пытаюсь отправить данные через Ajax-запрос от прослушивателя DOMContentLoaded в моем global.js
Следующий код выдает ошибку 400 (неверный запрос), и я не понимаю, почему. Если я отправлю ту же полезную нагрузку с помощью Postman на этот URL, я получу успех.
Global.js
document.addEventListener('DOMContentLoaded', function() {
var obj1 = document.getElementById('myObject');
// A bunch of logic to retrieve data to be sent to the server
// that if successful triggers a callback function
ProcessEvent: function (info){
// Update the database record here
//
alert("Making an AJAX call");
var xcall = $.ajax({
url: "http://127.0.0.1:3000/cashiers/jsonset",
type: 'post',
contentType: 'application/json',
data: obj1.items,
dataType: "json",
success: function(json) {
alert('Success : '+ json.reponse);
},
error: function(res){
alert("Error "+res.status+" with "+res.statusText);
}
}).done(function( msg ){
alert( "Data Saved: " + msg );
});
}
});