0

Доброго времени суток! Сразу предупрежу на всякий случай, что я в веб разработке новичок ) Возникла проблема с Ajax (как раз занимаюсь изучением). А именно - отправляю в свой PHP скрипт ajax-запрос:

<script>
        var user_id = document.getElementById("user_id").innerHTML;
        var date  = new Date;
        var month = date.getMonth();
        month++;
        var request = new XMLHttpRequest();
        request.open('GET','send_table_data.php?user_id=' + user_id, true);
        request.send();

        request.onreadystatechange = function(){
            while (request.readyState != 4){
                    return;
            }
            if(request.status != 200){
                    alert (request.status + ':' + request.statusText);
                }else{
                    var mas = JSON.parse(request.responseText);
                    alert (mas.month + " " + mas.comments[0]);
                }
        };
</script>

PHP-скрипт выглядит следующим образом:

<?php
require "database_connection.php";
require "current_date.php";
$user_id = $_REQUEST("user_id");
require "get_table_data.php";
 $array_of_data = array(
                        "month"    => $month_num,
                        "dates"    => $dates,
                        "hours"    => $hours,
                        "comments" => $comments);
  echo json_encode($array_of_data);  

Собственно, запрос не выполняется. Причина в переменной $user_id. Выводится следующее сообщение: Fatal Error: Function name must be a string in D:\OpenServer\OpenServer\domains\workingHours\send_table_data.php on line 4

send_table_data.php - это как раз тот второй фрагмент. Подскажите в чем причина, и как мне передать эту переменную $user_id. Заранее благодарен за помощь! )

1 ответ 1

1

Вы обращаетесь к массиву как к функции - круглые скобки

$user_id = $_REQUEST("user_id");

надо как к массиву - квадратные скобки

$user_id = $_REQUEST["user_id"];
1
  • Ну надо же! Такая мелочь! Действительно - простая невнимательность...Огоромное спасибо! 23 сен 2017 в 13:44

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.