javascript - jQuery AJAX - Not receiving JSON data when on localhost using XAMPP

I'm using this code:
$.ajax({
type: 'post',
url: "http://www.localhost/do_getmemes.php",
dataType: 'json',
data: {userid: userid, lastid: lastID},
success: function(data) {
console.log('bla');
console.log(data);
}
});
insidedo_getmemes.php
the post parameters are received successfully and the json is getting generated but I don't get it onsuccess
?? Console isn't showing anything. It works fine on the website but not when on localhost using XAMPP
It all works inside the php file, this is at the end:
file_put_contents('test.json', json_encode($array)); // file generated and not empty
echo json_encode($array);
What's the problem here?
EDIT:
AJAX usually works, I tested by getting simple string:
$.ajax({
url: "http://www.localhost/contact/text.php",
success: function(data) {
console.log(data) // got it
}
});
Answer
Solution:
The problem were irrelevant warnings which were also sent through the API back and causingparsererror SyntaxError: Unexpected token < in JSON at position 0
error.
Besides fixing them this is the way to ensure the APIs wills till work:
Disable the warnings inside the PHP file:
error_reporting(0);
ini_set('display_errors', 0);
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: zsh: command not found: php
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.