Ich versuche, Rest Web-Service-Anfrage mit JSON zu senden. Aber es wirft Ungültige Anfrage (http 400) Fehler. Die Anwendung benötigt keine Anmeldung. Ich habe verschiedene Formate ausprobiert, aber nichts half. Das Hauptproblem ist, dass JSON-Variablen dynamisch sind, d. H. Vom Benutzer eingegebene Werte.JSON mit Variablen in Javascript
var jsonObject = [];
var first_name = document.getElementById("firstName").value;
var last_name = document.getElementById("lastName").value;
var u_password = document.getElementById("password").value;
var u_password_hint = document.getElementById("passwordHint").value;
var email = document.getElementById("email").value;
var u_phone = document.getElementById("phone").value;
var u_organization = document.getElementById("organization").value;
var user = new User(first_name,last_name,email,u_password,u_password_hint,u_organization);
jsonObject.push(user);
var client = new XMLHttpRequest();
client.open("POST","https://instance.service-now.com/api/now/v1/table/user_registration_request");
client.setRequestHeader('Accept','application/json');
client.setRequestHeader('Content-Type','application/json');
client.send(body);
window.location = 'activate account.do';
function User(first_name, last_name, email, u_password_hint, u_password, u_organization) {
this.first_name = first_name;
this.last_name = last_name;
this.email = email;
this.u_password = u_password;
this.u_password_hint = u_password_hint;
this.u_organization = u_organization;
}