JS Помощь

Статус
Закрыто для дальнейших ответов.

Kreativne

Участник
Приветствую всех.
Недавно столкнулся с проблемой взял со старого скрипта модуль лотерея написанный на json+js+php+sql
При нажатии на кнопку вращать нечего не срабатывает проверил консоль ругается на data
код json

JavaScript:
function spinlottery() {
    $.ajax({
        type: 'POST',
        url: 'core/engine.php',
        beforeSend: function() {
            $("#spinbtn").hide();
        },
        data: {
            type: "spinlottery",
        },
        success: function(data) {
            var obj = jQuery.parseJSON(data);
            if (obj.success == "success") {
                var spins = $("#spins").html() - 1;
                $("#spins").html(spins);
                $("#panelWin").show();
                $("#panelWin").show();
                setTimeout(function() {
                    $("#numb1").html(obj.num1);
                }, 2500);
                setTimeout(function() {
                    $("#numb2").html(obj.num2);
                }, 2000);
                setTimeout(function() {
                    $("#numb3").html(obj.num3);
                }, 1000);
                setTimeout(function() {
                    $("#numb4").html(obj.num4);
                }, 100);
                setTimeout(function() {
                    toastr["success"]("Вы выиграли <b>" + parseFloat(obj.winSum).toFixed(3) + " <i class='fas fa-coins'></i></b>", "Успешно");;
                    $("#balance").html(parseFloat(obj.newbalance).toFixed(2));
                    $("#mob-balance").html(parseFloat(obj.newbalance).toFixed(2));
                    $("#balance").attr("balance", parseFloat(obj.newbalance).toFixed(2));
                    setTimeout(function() {
                        $("#panelWin").hide();
                        $("#numb1").html(0);
                        $("#numb2").html(0);
                        $("#numb3").html(0);
                        $("#numb4").html(0);
                        $("#spinbtn").show();
                    }, 1000);
                }, 4200);
            } else {
                if (obj.success == "error") {
                    $("#spinbtn").show();
                    toastr["error"](obj.mess, "Ошибка!");
                }
            }
        }
    });
}
код php

PHP:
if($type == "spinlottery")
{
if (!preg_match("/^[0-9a-zA-Z]+$/",$hash)){
    exit();
}
$sql_select = "SELECT lottery FROM maintenance WHERE id='1'";
$result = mysql_query($sql_select);
$row = mysql_fetch_array($result);
if($row)
{
    $offline = $row['lottery'];
}
$sql_select = "SELECT * FROM kot_user WHERE hash='$hash'";
$result = mysql_query($sql_select);
$row = mysql_fetch_array($result);
if($row)
{   
$balance = $row['balance'];
$user_id = $row['id'];
$ban = $row['ban'];
$login = $row['login'];
$lotteryspins = $row['lotteryspins'];
$user_id = $row['id'];
}
if($_SESSION['timestamp'] + 1 > time()){
  $error = 3;
  $fa = "error";
  $mess = "Пожалуйста, подождите...";
}
else{
  $_SESSION['timestamp'] = time();
}
if($lotteryspins <= 0){
  $error = 3;
  $fa = "error";
  $mess = "Закончились попытки!";
}
if($offline > 0){
  $error = 3;
  $fa = "error";
  $mess = "Эта функция временно недоступна!";
}
if($error == 0)
{
  $sql_select = "UPDATE kot_user SET lotteryspins = lotteryspins - '1' WHERE hash='$hash'";
  $result = mysql_query($sql_select);
  $rand1 = mt_rand(0,9);
  $rand2 = mt_rand(0,9);
  $rand3 = mt_rand(0,9);
  $rand4 = mt_rand(0,9);
  $rand = $rand1.$rand2.$rand3.$rand4;
  if($rand <= 9800){
      $prize = mt_rand(5,20) / 100;
  }
  elseif($rand >= 9801 && $rand <= 9900){
      $prize = mt_rand(50,200) / 100;
  }
  elseif($rand >= 9901 && $rand <= 9950){
      $prize = mt_rand(100,2000) / 100;
  } 
  elseif($rand >= 9951 && $rand <= 9990){
      $prize = mt_rand(1000,3000) / 100;
  }   
  elseif($rand >= 9991 && $rand <= 9998){
      $prize = mt_rand(2000,5000) / 100;
  }
  if($prize > $balance){
      $sql_update = "UPDATE kot_user SET balance = '$prize' * 10 WHERE hash='$hash'";
      $result = mysql_query($sql_update);
  }     
  $sql_select = "UPDATE kot_user SET balance = balance + '$prize' WHERE hash='$hash'";
  $result = mysql_query($sql_select);
  $insert_sql = "INSERT INTO `lotteryspins` (`user_id`, `number`, `result`) VALUES ('{$user_id}','{$rand}','{$prize}');";
  mysql_query($insert_sql) or die("" . mysql_error());
  $sql_select = "SELECT * FROM kot_user WHERE hash='$hash'";
  $result = mysql_query($sql_select);
  $row = mysql_fetch_array($result);
  $newbalance = $row['balance']; 
  $fa = "success";
}
// массив для ответа
$result = array(
    'success' => "$fa",
    'mess' => "$mess",
    'num1' => "$rand1",
    'num2' => "$rand2",
    'num3' => "$rand3",
    'num4' => "$rand4",
    'winSum' => "$prize",
    'new_balance' => "$newbalance",
    );
}
1611095390851.png
 

normalno

Местный
Замените своё на это:
Код:
function spinlottery() {
    $.ajax({
        type: "POST",
        url: "core/engine.php",
        beforeSend: function() {
            $("#spinbtn").hide();
        },
        data: {
            type: "spinlottery",
        },
        success: function(data) {
            var obj = jQuery.parseJSON(data);
            if (obj.success == "success") {
                var spins = $("#spins").html() - 1;
                $("#spins").html(spins);
                $("#panelWin").show();
                $("#panelWin").show();
                setTimeout(function() {
                    $("#numb1").html(obj.num1);
                }, 2500);
                setTimeout(function() {
                    $("#numb2").html(obj.num2);
                }, 2000);
                setTimeout(function() {
                    $("#numb3").html(obj.num3);
                }, 1000);
                setTimeout(function() {
                    $("#numb4").html(obj.num4);
                }, 100);
                setTimeout(function() {
                    toastr["success"]("Вы выиграли <b>" + parseFloat(obj.winSum).toFixed(3) + " <i class='fas fa-coins'></i></b>", "Успешно");
                    $("#balance").html(parseFloat(obj.newbalance).toFixed(2));
                    $("#mob-balance").html(parseFloat(obj.newbalance).toFixed(2));
                    $("#balance").attr("balance", parseFloat(obj.newbalance).toFixed(2));
                    setTimeout(function() {
                        $("#panelWin").hide();
                        $("#numb1").html(0);
                        $("#numb2").html(0);
                        $("#numb3").html(0);
                        $("#numb4").html(0);
                        $("#spinbtn").show();
                    }, 1000);
                }, 4200);
            } else {
                if (obj.success == "error") {
                    $("#spinbtn").show();
                    toastr["error"](obj.mess, "Ошибка!");
                }
            }
        }
    });
}
Больше всего что версии PHP разные :rolleyes:
 
Последнее редактирование:

Kreativne

Участник
Замените своё на это:
Код:
function spinlottery() {
    $.ajax({
        type: "POST",
        url: "core/engine.php",
        beforeSend: function() {
            $("#spinbtn").hide();
        },
        data: {
            type: "spinlottery",
        },
        success: function(data) {
            var obj = jQuery.parseJSON(data);
            if (obj.success == "success") {
                var spins = $("#spins").html() - 1;
                $("#spins").html(spins);
                $("#panelWin").show();
                $("#panelWin").show();
                setTimeout(function() {
                    $("#numb1").html(obj.num1);
                }, 2500);
                setTimeout(function() {
                    $("#numb2").html(obj.num2);
                }, 2000);
                setTimeout(function() {
                    $("#numb3").html(obj.num3);
                }, 1000);
                setTimeout(function() {
                    $("#numb4").html(obj.num4);
                }, 100);
                setTimeout(function() {
                    toastr["success"]("Вы выиграли <b>" + parseFloat(obj.winSum).toFixed(3) + " <i class='fas fa-coins'></i></b>", "Успешно");
                    $("#balance").html(parseFloat(obj.newbalance).toFixed(2));
                    $("#mob-balance").html(parseFloat(obj.newbalance).toFixed(2));
                    $("#balance").attr("balance", parseFloat(obj.newbalance).toFixed(2));
                    setTimeout(function() {
                        $("#panelWin").hide();
                        $("#numb1").html(0);
                        $("#numb2").html(0);
                        $("#numb3").html(0);
                        $("#numb4").html(0);
                        $("#spinbtn").show();
                    }, 1000);
                }, 4200);
            } else {
                if (obj.success == "error") {
                    $("#spinbtn").show();
                    toastr["error"](obj.mess, "Ошибка!");
                }
            }
        }
    });
}
Больше всего что версии PHP разные :rolleyes:
Попробую
 

Kreativne

Участник
Замените своё на это:
Код:
function spinlottery() {
    $.ajax({
        type: "POST",
        url: "core/engine.php",
        beforeSend: function() {
            $("#spinbtn").hide();
        },
        data: {
            type: "spinlottery",
        },
        success: function(data) {
            var obj = jQuery.parseJSON(data);
            if (obj.success == "success") {
                var spins = $("#spins").html() - 1;
                $("#spins").html(spins);
                $("#panelWin").show();
                $("#panelWin").show();
                setTimeout(function() {
                    $("#numb1").html(obj.num1);
                }, 2500);
                setTimeout(function() {
                    $("#numb2").html(obj.num2);
                }, 2000);
                setTimeout(function() {
                    $("#numb3").html(obj.num3);
                }, 1000);
                setTimeout(function() {
                    $("#numb4").html(obj.num4);
                }, 100);
                setTimeout(function() {
                    toastr["success"]("Вы выиграли <b>" + parseFloat(obj.winSum).toFixed(3) + " <i class='fas fa-coins'></i></b>", "Успешно");
                    $("#balance").html(parseFloat(obj.newbalance).toFixed(2));
                    $("#mob-balance").html(parseFloat(obj.newbalance).toFixed(2));
                    $("#balance").attr("balance", parseFloat(obj.newbalance).toFixed(2));
                    setTimeout(function() {
                        $("#panelWin").hide();
                        $("#numb1").html(0);
                        $("#numb2").html(0);
                        $("#numb3").html(0);
                        $("#numb4").html(0);
                        $("#spinbtn").show();
                    }, 1000);
                }, 4200);
            } else {
                if (obj.success == "error") {
                    $("#spinbtn").show();
                    toastr["error"](obj.mess, "Ошибка!");
                }
            }
        }
    });
}
Больше всего что версии PHP разные :rolleyes:
Ты шаришь в js, json?
 

Kreativne

Участник
Замените своё на это:
Код:
function spinlottery() {
    $.ajax({
        type: "POST",
        url: "core/engine.php",
        beforeSend: function() {
            $("#spinbtn").hide();
        },
        data: {
            type: "spinlottery",
        },
        success: function(data) {
            var obj = jQuery.parseJSON(data);
            if (obj.success == "success") {
                var spins = $("#spins").html() - 1;
                $("#spins").html(spins);
                $("#panelWin").show();
                $("#panelWin").show();
                setTimeout(function() {
                    $("#numb1").html(obj.num1);
                }, 2500);
                setTimeout(function() {
                    $("#numb2").html(obj.num2);
                }, 2000);
                setTimeout(function() {
                    $("#numb3").html(obj.num3);
                }, 1000);
                setTimeout(function() {
                    $("#numb4").html(obj.num4);
                }, 100);
                setTimeout(function() {
                    toastr["success"]("Вы выиграли <b>" + parseFloat(obj.winSum).toFixed(3) + " <i class='fas fa-coins'></i></b>", "Успешно");
                    $("#balance").html(parseFloat(obj.newbalance).toFixed(2));
                    $("#mob-balance").html(parseFloat(obj.newbalance).toFixed(2));
                    $("#balance").attr("balance", parseFloat(obj.newbalance).toFixed(2));
                    setTimeout(function() {
                        $("#panelWin").hide();
                        $("#numb1").html(0);
                        $("#numb2").html(0);
                        $("#numb3").html(0);
                        $("#numb4").html(0);
                        $("#spinbtn").show();
                    }, 1000);
                }, 4200);
            } else {
                if (obj.success == "error") {
                    $("#spinbtn").show();
                    toastr["error"](obj.mess, "Ошибка!");
                }
            }
        }
    });
}
Больше всего что версии PHP разные :rolleyes:
Да,php версии разные не подошло
 
Статус
Закрыто для дальнейших ответов.
Верх