I am trying to make an AJAX request in my Magento 2.1.8
custom module.
The Http Post Request is returning all of the data i expect it to in JSON format, However it is also adding on some of my html code after it.
What could be causing this?
returning JSON object:
if ($result->num_rows > 0) {
$return = [];
while($row = $result->fetch_assoc()) {
$return[] = [
'id' => $row['id'],
'name' => $row['name'],
'created' => $row['created'],
'posts' => $row['posts']
];
}
header('Content-type: application/json');
echo json_encode($return);
HTTP Post Request:
$.post("https://www.mywebsite.co.uk/forum/get/categories",
function(data, status){
console.log(data);
});
The data being returned is correctly formatted JSON object and then goes straight into html:
[{"id":"1","name":"Tanks - Sub Ohm","created":"15-01-18","posts":"1"}]<!doctype html>
<html lang="en-GB" dir="ltr" class="ltr">
<head >
<script>............
How can i remove the HTML part?
Thanks.