Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

141
Visualizações
Ajax php mysql loading issue

I'm trying to make a feature when I click on smaller picture to open a bigger one and show me some more additional details beside image itself. When the small image is clicked it's firing a function which pulling the id of the picture trough the dataset, and I'm trying send that data to .php file and then load from mysql database but all I get is an error. What am I doing wrong here? Am I doing mistake in js part or php one?

Same thing happens when I try to do it in a jquery version.

Here is vanilla.js version

function modalTitleLoad(e) {

let dataObj = e.target.dataset.id;

let xhr = new XMLHttpRequest();
xhr.open('GET', 'modalTitle.php');

xhr.onload = function () {
    if (this.status == 200) {
        let data = this.response;

        let datapass = dataObj;

        let output = '';
        output += data;

        document.querySelector('.modal__title').innerHTML = output;
    }
};
xhr.send();
}

jquery version:

function modalData(e) {
    let dataObj = e.target.dataset.id;

    $.ajax({
        type: 'GET',
        url: 'modalTitle.php',
        data: {
            datapass: dataObj,
        },
        success: function (data) {
            $('.modal__title').append(data);
        },
    });
}

modalData(event);

and there's the .php file:

<?php

$datapass = $_GET['datapass'];

$conn = mysqli_connect('localhost','root','','db');

$query = mysqli_query($conn, "SELECT description FROM content where timecode={$datapass}");

$data = mysqli_fetch_all($query, MYSQLI_ASSOC);

echo json_encode($data);

and here is the error:

Warning: Undefined array key "datapass" in C:\xampp\htdocs\Project\modalTitle.php on line 3

Fatal error: Uncaught TypeError: mysqli_fetch_all(): Argument #1 ($result) must be of type mysqli_result,
bool given in C:\xampp\htdocs\Project\modalTitle.php:9 Stack trace: #0 
C:\xampp\htdocs\Project\modalTitle.php(9): mysqli_fetch_all(false, 1) #1 {main} thrown in 
C:\xampp\htdocs\Project\modalTitle.php on line 9
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda