I am attempting to retrieve an Xmlhttp.response from a website by using the following code snippet:
var apiUrl = "http://somesite/someapicall/correctapiKey";
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("POST", apiUrl, false);
xmlHttp.setRequestHeader("Content-Type", "application/json");
var data {
"username": username,
"password": hashedPass,
"someOption": "true",
"someOtherOption": "true"
}
xmlHttp.send(data);
var response = xmlHttp.responseText;
var parsed = eval('(' + response + ')');
The code works when I manually input the strings for "username" and "password," but fails when using variables. I have checked for errors repeatedly without success.
I must be overlooking something minor, as I have been troubleshooting this issue all afternoon with no luck :(
Can anyone offer guidance or assistance, please?
Edit: The correct values for both the username and password variables are known and provided. The code has been updated to reflect the usage of these variables.