내가 가지고있는 PHP를 내 자바 스크립트에서 (POST) 전송 다음 JSON은자바 스크립트에서 PHP
// 기능 다음은이 버튼을 클릭하고 URL을 호출function boardToJSON() {
return JSON.stringify({
"pieces" : gPieces, // gpieces and gdestinations is an array
"destinations" : gDestinations,
"boardSize" : kBoardHeight // boardSize is an integer value 9
});
는로 패스를 포함한다 PHP 파일. 서버 측에
function makeMove() {
var move;
$.ajax({
type: 'POST',
url: url,
contentType: "application/json",
dataType: "json",
async: false,
data: boardToJSON(),
success: function(msg) {
move = msg;
},
error: function(jqXHR, exception) {
if (jqXHR.status === 0) {
alert('Unable to connect.\n Verify Network.');
} else if (jqXHR.status == 404) {
alert('Requested URL of HalmaAI not found. [404]');
} else if (jqXHR.status == 500) {
alert('Internal Server Error [500].');
} else if (exception === 'parsererror') {
alert('Data from HalmaAI was not JSON :(Parse failed.');
} else if (exception === 'timeout') {
alert('Time out error.');
} else if (exception === 'abort') {
alert('Ajax request aborted.');
} else {
alert('Uncaught Error.\n' + jqXHR.responseText);
}
}
});
(PHP에서) 나는이
$jsonString = file_get_contents("php://input");
$myJson = json_decode($jsonString);
echo $myJson["boardSize"]; // also tried $myJson.boardSize etc
문제처럼 그걸 얻기 위해 시도하고 내가 PHP에서 JSON을 디코딩 할 수없는 생각이다. 누군가 나를 안내 할 수 있을까요? 감사합니다
모르겠다. JSON을 게시하고 있지만 POST에서 파일을받지 못하는 파일에서 JSON을로드하려고 시도하는 PHP가 나타납니다. – Utkanos
@Utkanos는 원시 게시물 본문입니다 ... – PeeHaa
어떻게 데이터를 보냅니 까? 'var_dump()'는 당신에게 무엇을 말했습니까? – PeeHaa