<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<script src="/js/jquery.js"></script>
</head>
<body>
<button>버튼</button>
<script>
var arrayData = ["0-1", "6-2", "7-3"]; // array (단순 배열은 string변환 없이 그냥 넘기면된다)
/*
key, value형태의 배열(object)은 string형태로 변환이 필요하다.
*/
var objData = {firstName:"John", lastName:"Doe", age:46}; // object
objData = JSON.stringify(objData); // object를 string형태로 변환
$('button').click(function(event) {
$.ajax({
url: 'test_b.php',
type: 'post',
data: {
arrayData : arrayData, // array
objData : objData, // object string
}
})
.done(function(data, status, xhr) {
});
});
</script>
</body>
</html>
test_b.php
$arrayData = $_POST['arrayData']; // array
$objData = $_POST['objData']; // object String
$objData = json_decode($objData); // json형태의 string을 object로 변환 // stdClass(object로 형변환 시 생성)
foreach ($objData as $key => $value) {
// $value 데이터 확인
}
출처: http://mylife365.tistory.com/232 [변화에 적응하기]
댓글
댓글 쓰기