본문 바로가기
php

ajax 기본 / ajax Json

by 빡스웹 2022. 3. 26.
반응형

※기본

var string = $("form[name=frm").serialize();

$.ajax({
type: "POST",
url: "./ajax.php",
data: string,
cache: false,
async: false,
contentType : "application/x-www-form-urlencoded; charset=UTF-8",
success: function(data) {
alert(data);
}
});
return false;


====================================================


※json

$.ajax({
type: "POST",
url: "<?=G5_URL?>/sub/portfolio.ajax.php",
data: {wr_id : v, bo_table : bo_table},
dataType : "json",
cache: false,
async: false,
success: function(data) {
alert(data['wr_content']);
}
});
//return false;

json ajax 페이지에서 반환하는 처리방법echo json_encode(array('bo_table'=>$bo_table, 'sql'=>$sql, 'wr_subject'=>$row[wr_subject], 'wr_content'=>$row[wr_content]));

//bo_table=>$bo_table
//앞 bo_table 은 내가 만든 변수 / 뒤 bo_table 은 내가 스크립트 json을 통해 가지고 온 값

반응형

'php' 카테고리의 다른 글

php 엑셀 .xlsx 다운로드  (0) 2022.05.14
배열에서 특정 요소 삭제하기 unset()  (0) 2022.05.14
php gd 라이브러리 image circle crop  (0) 2022.03.26

댓글