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

ajax post방식으로 값을 전달해서 php에서 받을려고합니다 채택완료

권영민 8년 전 조회 18,802

위 내용처럼 할려고 하는데 form데이타 전체를 post방식으로 php에 전달하면서 페이지를 호출할려는데 도움을 주셨으면 좋겠습니다.

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

답변 3개

채택된 답변
+20 포인트
W
8년 전

config.form.update 에선 echo json_encode($var); 을 이용해서 json 형태로 뽑아줄수있구요 

 

config.form.update.php 

</span></p><p><span style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px; background-color: rgb(247, 247, 247);"><?php</span></p><p style="margin-left: 40px;"><span style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px; background-color: rgb(247, 247, 247);">$array = array('test'=>1,'test2'=>2);</span></p><p style="margin-left: 40px;"><span style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px; background-color: rgb(247, 247, 247);">echo json_encode($array);</span></p><p><span style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px; background-color: rgb(247, 247, 247);">?></span></p><p><span style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px; background-color: rgb(247, 247, 247);">

 

 

사용페이지

</span></p><p><span style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px; background-color: rgb(247, 247, 247);"><script type="text/javascript"> </span><br style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px;"><span style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px; background-color: rgb(247, 247, 247);">            var formData = jQuery('#form_test').serializeArray(); </span><br style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px;"><span style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px; background-color: rgb(247, 247, 247);">            var f = document.createElement('form'); </span><br style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px;">// <span style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px; background-color: rgb(247, 247, 247);">g=config&pmode=config.form.update 여기서 g/pmode 는  이미 form_test 라는 폼에 있으리라는 전제조건 하입니다.</span><br style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px;"><br style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px;"><span style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px; background-color: rgb(247, 247, 247);">            $("#bt_test").on('click',function () { </span><br style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px;"><span style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px; background-color: rgb(247, 247, 247);">                $.ajax({ </span><br style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px;"><span style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px; background-color: rgb(247, 247, 247);">                    url: "/page/index.php", </span><br style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px;"><span style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px; background-color: rgb(247, 247, 247);">                    type: "POST", </span></p><p>                dataType:'json',<br style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px;"><span style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px; background-color: rgb(247, 247, 247);">                    data: formData, </span><br style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px;"><span style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px; background-color: rgb(247, 247, 247);">                    success: function (r) { </span></p><span style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px; background-color: rgb(247, 247, 247);">                       console.log(r)</span><span style="background-color: rgb(247, 247, 247); color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px;">;</span><br style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px;"><span style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px; background-color: rgb(247, 247, 247);">                       console.log(r.test)</span><span style="background-color: rgb(247, 247, 247); color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px;">;</span><br style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px;"><span style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px; background-color: rgb(247, 247, 247);">                       console.log(r.test2)</span><span style="background-color: rgb(247, 247, 247); color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px;">;</span><p><span style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px; background-color: rgb(247, 247, 247);">                    }, </span><br style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px;"><span style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px; background-color: rgb(247, 247, 247);">                    error: function (jqXHR, textStatus, errorThrown) { </span><br style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px;"><br style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px;"><span style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px; background-color: rgb(247, 247, 247);">                    } </span><br style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px;"><span style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px; background-color: rgb(247, 247, 247);">                }) </span><br style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px;"><span style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px; background-color: rgb(247, 247, 247);">            }); </span><br style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px;"><span style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px; background-color: rgb(247, 247, 247);">        </script> </span><span style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px; background-color: rgb(247, 247, 247);"> </span></p><p><span style="color: rgb(51, 51, 51); font-family: 돋움, Dotum, sans-serif; font-size: 12px; background-color: rgb(247, 247, 247);">

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

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

플라이
8년 전

데이터 받는것은 $_POST 받는 방식으로 받으면 되고요

 

데이터 전달하는 ajax 방식은

 

참고 주소를 보시면 될듯 합니다.

 

http://findfun.tistory.com/400">http://findfun.tistory.com/400

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

답변에 대한 댓글 3개

권영민
8년 전
위 댓글소스 보고 수정사항이 있으면 얘기를 해주셨으면 좋겠습니다.
플라이
8년 전
위에 보면 전달 페이지가

page/?g=config&pmode=config.form.update

이건 get 방식으로 파라미터 전달도 사용하고 post도 사용하려는 부분처럼 보여지고요
전달 페이지가 이런 방식으로 전달이 되면 안되고요 별도 페이지로 해서 전달하셔서 처리하셔야 할겁니다.
권영민
8년 전
그러면 어떤식으로 해야될까요??? 예제같은 거를 도움주셨으면 좋겠습니다.
어떤식으로 호출을 해야되나요?

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

W
8년 전
내용이없습니다.

 

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

답변에 대한 댓글 1개

권영민
8년 전
<script type="text/javascript">
var formData = jQuery('#form_test').serializeArray();
var f = document.createElement('form');


$("#bt_test").on('click',function () {
$.ajax({
url: "/page/?g=config&pmode=config.form.update",
type: "POST",
data: formData,
success: function (formData, textStatus, jqXHR) {
location.href = "<?php echo G5_URL?>/page/?g=config&pmode=config.form.update";
},
error: function (jqXHR, textStatus, errorThrown) {

}
})
});
</script>

내용인데 그리고 나서 config.form.update 페이지를 호출해서 post값을 받아서 사용하고싶습니다.
formdata안에는 cf_title 등이 있습니다.

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

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

로그인