I am sending data using an XMLHttpRequest to my REST API in PHP and don't know how to get the response back. I am using echo
in my REST API if everything is ok, and data was processed.
JS code
var form = new FormData();
form.append("name", "Nicholas");
form.append("photo", $scope.imgs[0].file);
// send via XHR - look ma, no headers being set!
var xhr = new XMLHttpRequest();
xhr.onload = function() {
console.log("Upload complete.");
};
xhr.open("post", "http://yuppi.com.ua/server/rest/add.php?key=453sdfg3t&action=add", true);
xhr.send(form);
alert(xhr.responseXML);
And alert always returns NULL
PHP code:
$form = file_get_contents("php://input");
echo "Form: " .json_encode($form);
echo "Files: " .count($_FILES);
echo "POST: " .print_r($_POST);