PHP not receiving data from XMLhttprequest

好久不见. 提交于 2019-12-13 07:16:46

问题


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.


回答1:


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')



来源:https://stackoverflow.com/questions/31513934/php-not-receiving-data-from-xmlhttprequest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!