For some reason the post value isn't being shown even tho in var_dump it shows that it's there.

You can see that the $_POST["ajaxMonth"] has a string value of "2" in the first image however when I echo it, it has nothing as show in the second image. Here is my php
$ajaxMonth = $_POST["ajaxMonth"];
$ajaxYear = $_POST["ajaxYear"];

var_dump($_POST);

echo '<div class="day">'. $ajaxMonth .'</div>';
$ajaxMonth = $_POST["ajaxMonth"];
$ajaxYear = $_POST["ajaxYear"];

var_dump($_POST);

echo '<div class="day">'. $ajaxMonth .'</div>';
Here is my Ajax
// Show the days with events if there is events in that certain day
$(".days").load('model/showDayCalendarEvents.php', {ajaxPrevLastDayNum:prevLastDayNum, ajaxLastDayWeekday:lastDayWeekday, ajaxLastDayWeekDate:lastDayWeekDate, ajaxFirstDayNumber:firstDayNumber, $ajaxMonth:month, $ajaxYear:year});
// Show the days with events if there is events in that certain day
$(".days").load('model/showDayCalendarEvents.php', {ajaxPrevLastDayNum:prevLastDayNum, ajaxLastDayWeekday:lastDayWeekday, ajaxLastDayWeekDate:lastDayWeekDate, ajaxFirstDayNumber:firstDayNumber, $ajaxMonth:month, $ajaxYear:year});
No description
No description
16 Replies
Jochem
Jochem10mo ago
you've got a superfluous $ in the variable name I'm guessing your name attribute in your input tag is something like name="$ajaxYear" or something?
kingtigerknight
kingtigerknightOP10mo ago
no, the the $_POST["ajaxMonth"] is from the ajax itself.
Jochem
Jochem10mo ago
in the screenshot, the key is called "$ajaxMonth"
kingtigerknight
kingtigerknightOP10mo ago
yes, thats from the ajax $ajaxMonth:month
Jochem
Jochem10mo ago
I'm saying if your var_dump shows $ajaxMonth as a key, and you're accessing the key ajaxMonth on $_POST, those are not the same thing try $ajaxMonth = $_POST['$ajaxMonth'];
kingtigerknight
kingtigerknightOP10mo ago
dosen't work
Jochem
Jochem10mo ago
how are you submitting your POST?
kingtigerknight
kingtigerknightOP10mo ago
by ajax
Jochem
Jochem10mo ago
can you share how you populate that?
kingtigerknight
kingtigerknightOP10mo ago
like this one?
$(".days").load('model/showDayCalendarEvents.php', {ajaxPrevLastDayNum:prevLastDayNum, ajaxLastDayWeekday:lastDayWeekday, ajaxLastDayWeekDate:lastDayWeekDate, ajaxFirstDayNumber:firstDayNumber, $ajaxMonth:month, $ajaxYear:year});
$(".days").load('model/showDayCalendarEvents.php', {ajaxPrevLastDayNum:prevLastDayNum, ajaxLastDayWeekday:lastDayWeekday, ajaxLastDayWeekDate:lastDayWeekDate, ajaxFirstDayNumber:firstDayNumber, $ajaxMonth:month, $ajaxYear:year});
There was another one that worked I made. The values were shown there, however I can't use this one since there for different things
$('.events').load('model/loadCalendarEvents.php', {ajaxDay:Number(date), $ajaxMonth:month, $ajaxYear:year});
$('.events').load('model/loadCalendarEvents.php', {ajaxDay:Number(date), $ajaxMonth:month, $ajaxYear:year});
Jochem
Jochem10mo ago
why is the $ there on ajaxMonth in this snippet?
kingtigerknight
kingtigerknightOP10mo ago
thats what my teacher put as for the name.
Jochem
Jochem10mo ago
try removing the $ sign there?
kingtigerknight
kingtigerknightOP10mo ago
dosen't work. I know that it works tho because in the 2nd snippet it's the same name but it works.
Jochem
Jochem10mo ago
then I don't know. The most obvious thing here is that the key in the vardump ($ajaxMonth) doesn't match the key you're accessing (ajaxMonth). If that's not it, I'm blaming gremlins.
ἔρως
ἔρως10mo ago
i second this $ajaxMonth:month, $ajaxYear:year <-- this is the issue you have to remove the $ from the name also, make sure that you're actually sending what you expect to receive
Want results from more Discord servers?
Add your server