A
A
Alexey2020-05-10 01:57:44
AJAX
Alexey, 2020-05-10 01:57:44

Why is the AJAX request not firing?

Why doesn't a function fire in a PHP AJAX request?

AJAX:

$(document).ready(function () {
  emojis();
  $('#loginmsg').html('<h2>Загружаем, ожидайте..</h2>');
    getuser();
});

function getuser() {
    $.ajax({
        type: "POST",
        url: "api/public.php",
        data: {
            GetIPS_user: 'yes'
        },
        success: function(response)
        {
            $('#loginmsg').html(response);
        },
        error : function(XMLHttpRequest, textStatus, errorThrown)
        {
          $('#loginmsg').html("<div class='loginerr' style='font-size: 12px; color: #fff; padding: 1%; border-radius: 3px; border: 1px solid #ff4444; text-align: center; margin: 5%;'><span style='color: #ff4444;'><i class='fas fa-exclamation-circle'></i></span> Произошла неизвестная ошибка.</div>");
        }
    
      });
}

PHP:
function GetIPS_user() {
  $security_cookie = $_COOKIE['ips4_device_key'];

  $link = mysqli_connect('localhost', 'invision', 'f456ajFER0', 'invision');

  $sql = "SELECT member_id from core_members_known_devices WHERE device_key = '$security_cookie'";

    $result = mysqli_query($link, $sql);

    $num_rows = $result->num_rows;

    if($num_rows == 0)
    {
        echo "<div class='loginerr' style='font-size: 12px; color: #fff; padding: 1%; border: 1px solid #fff; text-align: center; margin: 5%;'>Произошла неизвестная ошибка.<br/>ID Ошибки: 99#unknown-error/login</div><div style='color: #ccc; text-align: center; font-size: 12px; margin-bottom: 4%;'>Обновите страницу или попробуйте зайти позже.</div>";
    }
    else
    {

        while($row = mysqli_fetch_array($result, MYSQLI_BOTH))
        {
            echo 'Ваш ID на форуме: '.$row['0'].'<br>Авторизация успешно, идентификатор получен!';
        }

    mysqli_close($link);
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
FANTASANTA, 2020-05-10
@FANTASANTA

Because you are using the ID more than once. Use class instead of ID.

T
ThunderCat, 2020-05-10
@ThunderCat

data: {GetIPS_user: 'yes'},
In general, it is not used anywhere (?)
function GetIPS_user() {...}- ok, you created it, what's next? You don't use it anywhere. Or do you somehow strangely understand the essence of Ajax requests in general ...
look at the console, the network section, while sending
- see what your request sends in the request body
- see what the server returned
, but all this is provided that something will work on the server

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question