I use AJAX all the time and never have a problem. All of a sudden every one of my AJAX calls to a variety of server side PHP pages is returning a 200 response and its not recognizing the JSON return. When I visit the PHP page get_message_list.php
directly it is perfectly echoing a JSON encoded array as expected {"msg_count":2}
, so I know that is correct. If I change the dataType to “text” to test it just outputs the current page HTML. This just started happening and I have no idea what Im doing wrong?!
$.ajax({
type:'POST',
url: 'functions/get_message_list.php',
data:{"test":1},
contentType: 'application/json;charset=UTF-8',
dataType : "json",
success:function(data){
alert(data.msg_count);
},error: function (request, status, error) {
alert(request.status);
}
})
Here is the PHP page code:
session_start();
include_once('../system/db.php');
$my_uid = $_SESSION['user']['user_id'];
$query = "SELECT * FROM msg_connect WHERE from_id = {$my_uid}
OR to_id = {$my_uid} ";
$result = mysqli_query($connect, $query);
$mail_list_rows = mysqli_num_rows($result);
echo json_encode(array("msg_count"=>$mail_list_rows));
exit();
5