테스트 사이트 - 개발 중인 베타 버전입니다

배열로 form으로 넘겼는데 값이 안나오네요? 채택완료

세진컴퓨터랜드 2년 전 조회 2,408

특정값을 모아서 가져와야 되서 input name을 배열로 넘겼는데

값이 안나오네요.

</p>

<pre>
<?php
include_once ('./_common.php');
include_once (G5_PATH.'/head.php');

?>
<script type="text/javascript">

$(document).ready(function(){
    $(document).on("click", "button", function(){
        $.ajax({
            url: "ajax.php",
            method: "post",
            dataType: "json",
            async: false,
            data: $("#test_form").serialize(),
            sucess: function(data){
                console.log(data);
            }
        });
    });

});
</script>

<form id="test_form" action="ajax.php">
    <input type="text" name="id[]" id="" value="강백호">
    <input type="text" name="id[]" id="" value="서태웅">
    <input type="text" name="id[]" id="" value="정대만">
    <input type="text" name="num[]" id="" value="10">
    <input type="text" name="num[]" id="" value="11">
    <input type="text" name="num[]" id="" value="14">
    <button type="button">버튼</button>
</form>

<?php
include_once (G5_PATH.'/tail.php') ;
</pre>

<p>

 

</p>

<pre>
<?php
include_once('./_common.php');

foreach($_POST as $key => $value){
   $arrayValues[$key] = $value;
}
//$target_table = "g5_write_".$arrayValues['target_table'];
//$sql = "select * from {$target_table}";
//
//$result = sql_query($sql);
//
//for($i=0;$i<sql_num_rows($result);$i++){
// $data[$i] = sql_fetch_array($result);
//}


echo json_encode($arrayValues, JSON_UNESCAPED_UNICODE);</pre>

<p>

댓글을 작성하려면 로그인이 필요합니다.

답변 3개

채택된 답변
+20 포인트

</p>

<p>// button 타입 button 보다는 submit으로 하고 

// $(document).on("submit", "button", function(){ => $("#test_form").submit(function(event) { 

submit 이벤트로 하면 좋지 않을가 생각해봅니다</p>

<p>

// 데이터 부분 수정

data: JSON.stringify($("#test_form").serializeJSON())</p>

<p> </p>

<p>// 받는쪽

$_DATA = json_decode(file_get_contents('php://input'), true);

print_r($_DATA);</p>

<p>

 

이렇게 확인하면 나오지 않을가요

 

 

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

sucess: function(data){

                console.log(data);

           

결과가 어떻게 나오나요

 

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

근데 왜 포스트를 저렇게 쓰는거에요?

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인