javascript - Getting post data from ajax request php

I keep getting null values with the below code:
Ajax request:
formData = {
u: "3959eeadb32e02b85a792e21c",
id: "6d7613df26"
};
$.ajax({
url: "/includes/loginProcess.php",
type: "POST",
crossDomain: true,
contentType: 'application/json',
data: formData,
dataType: "json",
success: function(data) {
console.log(data);
},
error: function() {
}
});
PHP Processing:
$data = array();
$data['u'] = $_POST["u"];
$data['id'] = $_POST["id"];
echo json_encode($data);
{u: null, id: null} is logged in the success function. Any ideas?
This is on an AWS Lightsail instance BTW... is there some server config I'm missing maybe?
Answer
Solution:
contentType: 'application/json'
is wrong. You aren't sending JSON. This will confuse the server. Just remove that line and it will work fine.
(AlsocrossDomain: true
almost certainly isn't needed here (and probably doesn't do whatever you think it does)).
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: you must enable the openssl extension in your php.ini to load information from https://repo.packagist.org
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.