ajax 질문 입니다.
본문
목록에서 아래처럼 사용하는데요.
값이 넘어가기는 하는데 db에 저장이 안되고 있어요..
<form name="order_frm_<?php echo $i ?>" id="order_frm_<?php echo $i ?>" action="" method="post" enctype="multipart/form-data" autocomplete="off">
<!-- 클라이언트 정보 -->
<input type="hidden" name="order_company_id_<?php echo $i ?>" value="<?php echo $member['mb_id'] ?>">
<input type="hidden" name="order_company_name_<?php echo $i ?>" value="<?php echo $member['mb_name'] ?>">
<input type="hidden" name="order_manager_name_<?php echo $i ?>" value="<?php echo $member['mb_1'] ?>">
<input type="hidden" name="order_company_tel_<?php echo $i ?>" value="<?php echo $member['mb_tel'] ?>">
<input type="hidden" name="order_company_hp_<?php echo $i ?>" value="<?php echo $member['mb_hp'] ?>">
<input type="hidden" name="order_company_profile_<?php echo $i ?>" value="<?php echo $member['mb_profile'] ?>">
<!-- 파트너 정보 -->
<input type="hidden" name="partner_id_<?php echo $i ?>" value="<?php echo $row['mb_id'] ?>">
<input type="hidden" name="partner_name_<?php echo $i ?>" value="<?php echo $row['mb_name'] ?>">
<input type="hidden" name="partner_tel_<?php echo $i ?>" value="<?php echo $row['mb_tel'] ?>">
<input type="hidden" name="partner_hp_<?php echo $i ?>" value="<?php echo $row['mb_hp'] ?>">
</form>
if(confirm("작업을 의뢰 하시겠습니까?")) {
$.ajax({
url: 'ajax.partner_order_list.php',
type: "POST",
data: $('#order_frm_<?php echo $i ?>').serialize(),
dataType: "text",
error: function(xhr, status, error){
alert(error);
},
async: false,
cache: false,
success : function(res){
if(res) { // 성공
alert('작업 의뢰가 완료 되었습니다.');
location.href='<?php echo G5_THEME_MSHOP_URL ?>/order_client.php';
}
}
});
}
ajax.partner_order_list.php 파일
<?
include_once('./_common.php');
if($_POST['order_company_id'] == '')
alert('정상적인 접근이 아닙니다.');
$sql = " insert into `tbl_order`
set partner_id = '{$partner_id}',
partner_name = '{$partner_name}',
partner_tel = '{$partner_tel}',
partner_hp = '{$partner_hp}',
order_company_id = '{$order_company_id}',
order_company_name = '{$order_company_name}',
order_manager_name = '{$order_manager_name}',
order_company_tel = '{$order_company_tel}',
order_company_hp = '{$order_company_hp}',
order_company_profile = '{$order_company_profile}'
";
sql_query($sql);
echo "ok";
?>
!-->!-->
답변 3
ajax.partner_order_list.php
와 맞추려면
<input type="hidden" name="order_company_id_<?php echo $i ?>"
==>
<input type="hidden" name="order_company_id"
$.ajax({
url: 'ajax.partner_order_list.php',
type: "POST",
data: $('#order_frm_<?php echo $i ?>').serialize(),
dataType: "text",
error: function(xhr, status, error){
alert(error);
},
async: false,
cache: false,
success : function(res){
if(res) { // 성공
alert('작업 의뢰가 완료 되었습니다.');
location.href='<?php echo G5_THEME_MSHOP_URL ?>/order_client.php';
}
}
});
ajax의 스크립트에서 data의 i 값이 정확히 인지가 되고 있나요?
name이 order_company_id_1 형태이기 때문에..
$order_company_id_1 형태로 받아야 되어서 생기는 문제입니다.
방법1)
* ajax 처리 파일 (order_company_id_1 형태를 $order_company_id 형태로 받기)
<?php
include_once('./_common.php');
foreach ($_POST as $key => $value) {
$key = preg_replace('/_[0-9]/', '', $key);
${$key} = $value;
}
답변을 작성하시기 전에 로그인 해주세요.