var userData = {
"emailAddress": document.getElementById('emailAddress').value,
"password": document.getElementById('password').value
}
var userDataString = JSON.stringify(userData);
alert(userDataString);
var url = "url";
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
alert('connected..');
}
};
xmlhttp.open("POST", url, true);
xmlhttp.send(userDataString);
$.ajax({
type: "POST",
URL: "login.php",
contentType: "application/json",
CrossDomain: true,
data: JSON.stringify(userData),
dataType: 'json',
success: function(data) {
alert("success");
var response = jQuery.parseJSON(data);
alert(response);
I have a login form that contains user ID and password. I need to convert the entered information into JSON and send it to the server. However, I'm getting a JSON parsing error. I've been trying for hours but can't find the mistake. Can you please help me identify where I'm going wrong?