Skip to content
Advertisement

PHP wont return anything to AJAX when adding certain Function

I am confused my PHP wont return anything to AJAX when I added my decrypt Function

MY PHP Files:

$key = "Secret Key";
function decryptthis($data, $key)
{
    $encryption_key = base64_decode($key);
    list($encrypted_data, $iv) = array_pad(explode('::', base64_decode($data), 2), 2, null);
    decryptthis($encrypted_data, 'aes-256-cbc', $encryption_key, 0, $iv);
}

session_start();
$user = $_SESSION['username'];
$bulan = $_POST['bulan'];
$tahun = $_POST['tahun'];
$res = array();

$result = mysqli_query($con, "select * from tb_payslip where NIP ='$user' AND bulan='$bulan' AND tahun='$tahun'");
$rowCheck = mysqli_num_rows($result);
if ($rowCheck > 0) {
    while ($row = mysqli_fetch_array($result)) {

        $res['cabang'] = $row['cabang'];
        $res['NIP'] = $row['NIP'];
        $res['u_gaji_pokok'] = decryptthis("$row[u_gaji_pokok]", $key);//When i added this function wont return anything
        $res['bulan'] = $row['bulan'];
        $res['tahun'] = $row['tahun'];
        $res['response'] = "ok";
    }
}

echo json_encode($res);

MY AJAX that would return the result:

$("#generate-payslip").click(function (e) {
    e.preventDefault();
    $.ajax({
        type: 'POST',
        url: 'generate-payslip.php',
        data: $('.form-pdf').serialize(),
        dataType: 'json',
        success: function (resp) {
            if (resp.response == "ok") {

                $('#payslip-title').html("SLIP GAJI " + returnbulan(resp.bulan) + " " + resp.tahun);
                $("#cabang").html(resp.cabang);
                $('#u_gaji_pokok').html(resp.u_gaji_pokok);
            }
        })

When I run the code, my AJAX would return nothing, but when I delete the Decryptthis Function, the AJAX will Return all the result as intended.

Please Help I am really confused as to why in wont work

Advertisement

Answer

You have infinite loop right there. decryptthis() is calling itself

remove the inner one and you should be fine.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement