D
D
del9937882016-03-25 15:12:16
PHP
del993788, 2016-03-25 15:12:16

Why is there an empty response in the request to the DLE database?

Hello. Look at the code.

<a href="#" onclick="giveMeUsername('1');return false;">Показать имя пользователя</a>

function giveMeUsername(user_id) {
    $.ajax({
    	type: "GET",
    	url: "/engine/ajax/givemeuser.php", // Имя файла к которому будет идти AJAX запрос
    	data: "user_id="+user_id, // ID юзера которого будем выбирать
    	success: function(data){
            alert(data); // Итог: Алерт с Именем пользователя
    	}
    });
}

<?php
define( 'DATALIFEENGINE', true );
define( 'ROOT_DIR', substr( dirname(  __FILE__ ), 0, -12 ) );
define( 'ENGINE_DIR', ROOT_DIR . '/engine' );

require_once ENGINE_DIR . '/classes/mysql.php';
require_once ENGINE_DIR . '/data/dbconfig.php';

$user_id = intval($_GET['user_id']);

$USER = $db->super_query("SELECT * FROM " . USERPREFIX . "_users WHERE user_id='{$user_id}' ");

echo $USER['username'];

?>

In theory, I should see my nickname, but I do not see it. Just an empty window. Why? maybe there is an error somewhere?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Kozlov, 2016-03-25
@del993788

From the manual, the data field is an object.

$.ajax({
  method: "POST",
  url: "some.php",
  data: { name: "John", location: "Boston" }
})
  .done(function( msg ) {
    alert( "Data Saved: " + msg );
  });

Or write like this:
function giveMeUsername(user_id) {
    $.ajax({
    	type: "GET",
    	url: "/engine/ajax/givemeuser.php?user_id="+user_id, // Имя файла к которому будет идти AJAX запрос
    	   	success: function(data){
            alert(data); // Итог: Алерт с Именем пользователя
    	}
    });
}

also check if the user ID is coming
$user_id = intval($_GET['user_id']);
echo $userid;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question