Good day! Immediately I’ll warn you just in case that I’m new to web development) There was a problem with Ajax (I’m just studying). Namely, I send an ajax request to my PHP script:
<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> The PHP script looks like this:
<?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); Actually, the request is not executed. The reason is in the variable $user_id . The following message is Fatal Error: Function name must be a string in D:\OpenServer\OpenServer\domains\workingHours\send_table_data.php on line 4 : 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 is just that second snippet. Tell me what is the reason, and how can I pass this $user_id variable. Thanks in advance for your help! )