I have a super simple JS code that POSTs to my local server. Both JS and PHP are on localhost so I'm not worrying about cross site issues at the moment. Here's my JS:
var ENDPOINT_BASE = '';
var ENDPOINT_USER_LOGIN = { url: '/user/login', method: 'POST'};
var ENDPOINT_USER_REGISTER = { url: '/user/register', method: 'POST'};
var toSend = {'credentials': { 'email':'1', 'password':'123'}};
$.ajax({
method: ENDPOINT_USER_LOGIN.method,
url: ENDPOINT_BASE + ENDPOINT_USER_LOGIN.url,
contentType: "application/json",
data: toSend
});
My PHP is simply:
<?php
print_r($_POST);
In the Chrome debugger I can see the network call be made, however the Response received in $_POST
is always empty, ie it prints out Array()
.
If I add something like echo "abc";
in the PHP I can see it in the response, so it is hitting that URL correctly.
I'm using jQuery 2.1.4.
The JS console isn't printing out any error messages.
Any ideas what could be wrong? Thanks!