alert 이나 echo 나 메시지 출력이 안되는 이유 문의
위 슬롯머신을 사용하고있습니다.
동작은 다 잘되는데
메시지 출력이 안되는데 이유를 모르겠습니다.
slot.php 에서는 alert 이나 echo 나 메세지가 다 잘 출력이 되는데
//slot.php
// spin.php 호출 부분 464 line
getSpin = function() {
spin[0] = -1;
$.ajax({
url: "spin.php",
type: "get",
datatype: "json",
async: false,
success: function(data) {
spin[0] = JSON.parse(data)['slot1'];
spin[1] = JSON.parse(data)['slot2'];
spin[2] = JSON.parse(data)['slot3'];
},
complete: function(data) {},
error: function(xhr, status, error) {}
});
},
spin.php 여기에선 alert 이나 echo 나 메세지가 출력되질 않습니다.
//spin.php 시작부분
<?php
include_once('../../common.php');
define('cherry', 0);
define('orange', 1);
define('prune', 2);
define('bell', 3);
define('seven', 4);
define('bar1', 5);
define('bar2', 6);
define('bar3', 7);
define('anyBar', 8);
if($member['mb_point'] < 10000) {
alert('슬롯머신 배팅에 필요한 포인트가 없습니다.', '../../index.php');
}
메세지가 출력이 안되고 게임이 뻣어? 버리는 현상이 발생합니다.
어째서 메세지 출력이 안되는지 모르겠네요..
답변 6개 / 댓글 2개
* slot.php
//slot.php
// spin.php 호출 부분 464 line
getSpin = function() {
spin[0] = -1;
$.ajax({
url: "spin.php",
type: "get",
datatype: "json",
async: false,
success: function(data) {
error = JSON.parse(data)['error'];
if (error == 'no_point') {
alert('슬롯머신 배팅에 필요한 포인트가 없습니다.');
return false;
}
spin[0] = JSON.parse(data)['slot1'];
spin[1] = JSON.parse(data)['slot2'];
spin[2] = JSON.parse(data)['slot3'];
},
complete: function(data) {},
error: function(xhr, status, error) {}
});
},
* spin.php
<?php
include_once('../../common.php');
define('cherry', 0);
define('orange', 1);
define('prune', 2);
define('bell', 3);
define('seven', 4);
define('bar1', 5);
define('bar2', 6);
define('bar3', 7);
define('anyBar', 8);
if ($member['mb_point'] < 10000) {
die(json_encode(array('error'=>'no_point')));
}
"exit;" 를 추가해줘야 합니다.
추가하지 않으면 하위 코드까지 모두 실행됩니다.
if($member['mb_point'] < 10000) {
// echo ('슬롯머신 배팅에 필요한 포인트가 없습니다.', '../../index.php');
echo json_encode( array( 'error'=>'error', 'msg'=>'슬롯머신 배팅에 필요한 포인트가 없습니다.' ) );
exit; // 추가되어야 함.
}
지난 질문에 있는 소스를 보면
<?php
...
if($member['mb_point'] < 10000) {
echo ('슬롯머신 배팅에 필요한 포인트가 없습니다.', '../../index.php');
}
...
echo '{"slot1":'.$spin[0].',"slot2":'.$spin[1].',"slot3":'.$spin[2].'}';
...
이렇게 되어 있습니다.
둘 다 json 형식으로 출력해야 합니다.
<?php
...
if($member['mb_point'] < 10000) {
//echo ('슬롯머신 배팅에 필요한 포인트가 없습니다.', '../../index.php');
echo json_encode( array(
'error=>'error', 'msg'=>'슬롯머신 배팅에 필요한 포인트가 없습니다.')
) );
}
...
echo '{ "error":"ok", "slot1":'.$spin[0].',"slot2":'.$spin[1].',"slot3":'.$spin[2].'}';
...
그리고
success: function(data) {
spin[0] = JSON.parse(data)['slot1'];
spin[1] = JSON.parse(data)['slot2'];
spin[2] = JSON.parse(data)['slot3'];
},
이 부분은
success: function(data) {
var tmp= JSON.parse(data);
if( tmp.error=='error') { alert( tmp.msg); }
else { /*기존대로 */ }
},
답변에 대한 댓글 1개
spin.php
[code]
<?php
include_once('../../common.php');
define('cherry', 0);
define('orange', 1);
define('prune', 2);
define('bell', 3);
define('seven', 4);
define('bar1', 5);
define('bar2', 6);
define('bar3', 7);
define('anyBar', 8);
if($member['mb_point'] < 10000) {
// echo ('슬롯머신 배팅에 필요한 포인트가 없습니다.', '../../index.php');
echo json_encode( array( 'error'=>'error', 'msg'=>'슬롯머신 배팅에 필요한 포인트가 없습니다.' ) );
}
insert_point($member['mb_id'], -10, 'Vegas플레이 비용');
$profits = array(
array(10, 30, 120), // cherry
array(0, 0, 100), // orange
array(0, 0, 200), // prune
array(0, 0, 500), // bell
array(0, 0, 5000), // seven
array(0, 0, 300), // bar1
array(0, 0, 1000), // bar2
array(0, 0, 2000), // bar3
array(0, 0, 80) // anybar
);
$slotName = array(
'?',
'?',
'?',
'?',
'?',
'1️',
'2️',
'3️',
);
$slots = array(
array(
cherry, orange, cherry, bar2, prune, bar1, bell, orange,
cherry, orange, bar3, prune, cherry, bell, bar1, orange,
cherry, seven, prune, orange, cherry
),
array(
orange, cherry, bar1, prune, orange, bar2, bell, cherry,
bar3, orange, bar1, prune, cherry, orange, bell, bar2,
seven, cherry, bar1, prune, orange, cherry
),
array(
orange, cherry, bar1, bell, bar3, prune, orange, bar2,
cherry, prune, bell, seven, bar1, bar3, orange, bar2,
cherry, bell, prune, bar1, orange
)
);
$maxSpin = array(20, 21, 20);
$spin = array();
$spin[0] = rand(0, $maxSpin[0]);
$spin[1] = rand(0, $maxSpin[1]);
$spin[2] = rand(0, $maxSpin[2]);
$matchCount = 0;
$matched = $slots[0][$spin[0]];
if($matched == $slots[1][$spin[1]]) {
$matchCount++;
} else if(($matched > seven) && ($slots[1][$spin[1]] > seven)) {
$matched = anyBar;
$matchCount++;
}
if($matched == $slots[2][$spin[2]]) {
if($matchCount > 0) $matchCount++;
} else if(($matched > seven) && ($slots[2][$spin[2]] > seven)) {
if($matchCount > 0) {
$matched = anyBar;
$matchCount++;
}
}
if($profits[$matched][$matchCount] != 0) {
insert_point($member['mb_id'], $profits[$matched][$matchCount], G5_TIME_YMD.' Vegas플레이 수익 ['.$slotName [$slots[0][$spin[0]]].$slotName [$slots[1][$spin[1]]].$slotName [$slots[2][$spin[2]]].']');
}
echo '{"error":"ok", "slot1":'.$spin[0].',"slot2":'.$spin[1].',"slot3":'.$spin[2].'}';
$sql =" UPDATE counter SET cnt_1 =cnt_1+1, cnt_datetime = now() WHERE cnt_pg_name = 'vegas_play' AND DATE(cnt_datetime) = DATE(NOW()) AND cnt_id = '$member[mb_id]' ";
$result = sql_query($sql);
[/code]
slot.php
[code]
getSpin = function() {
spin[0] = -1;
$.ajax({
url: "spin.php",
type: "get",
datatype: "json",
async: false,
success: function(data) {
var tmp= JSON.parse(data);
if( tmp.error=='error') { alert( tmp.msg); }
else {
spin[0] = JSON.parse(data)['slot1'];
spin[1] = JSON.parse(data)['slot2'];
spin[2] = JSON.parse(data)['slot3'];
}
},
complete: function(data) {},
error: function(xhr, status, error) {}
});
},
[/code]
답변을 작성하려면 로그인이 필요합니다.