Can I send a request as shown below? With parameters, a JSON style object is assigned. I get an error. But when I use the REST client and select RAW data, this is normal. I guess I wrote the wrong code. How to send raw JSON data in JavaScript? Can anyone help me?
xmlhttp = new XMLHttpRequest(); var url = "https://someURL"; xmlhttp.open("POST", url, true); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.onreadystatechange = function () { //Call a function when the state changes. if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { alert(xmlhttp.responseText); } } var parameters = { "username": "myname", "password": "mypass" }; // Neither was accepted when I set with parameters="username=myname"+"&password=mypass" as the server may not accept that xmlhttp.send(parameters);
anaconda_wly
source share