1

Hi I am sending data to a php script like so:

function ajax(url,data,success) {
    var request = new XMLHttpRequest();
    request.open("POST", url);
    request.onreadystatechange = function(object) {
        if(request.readyState === 3) {
            success(request);
        }
    };
    request.setRequestHeader("Content-Type","application/json")
    request.send(data);
}

The data being sent is a stringifyed javascript object. The post definitely works and the object shows in the payload section in chromes dev tools. But the php script I am sending to request object is empty. The php script's content type is set to json.

frank astin
  • 23
  • 1
  • 8

1 Answers1

4

Sounds like you're experiencing quite a well-known issue (some info here: PHP "php://input" vs $_POST)

You should be able to access the data with file_get_contents('php://input')

Community
  • 1
  • 1
nealio82
  • 2,611
  • 1
  • 17
  • 19
  • Cheers, that did it. I presume jQuery's ajax converts it across to url-form vars before sending. – frank astin Jul 20 '15 at 10:27
  • You're welcome. It's quite a common issue - I've had the same problem before and hence how I was able to guess that's what you were having! :D – nealio82 Jul 20 '15 at 11:41