I'm trying to update $_POST['category'] by clicking a button. I'm trying to achieve this using AJAX (for the first time), as read on several other pages here. My JS function currently updates the correct value in the console, but it cannot actually update the POST to the correct value, or at least that's what I assume. I need help trying to get the value of a POST so that I can use it as a value in PHP.
Main PHP File
<div class="subcategory text_markup_subtitle"> <ul> <li class="subhead" value="mobiliteit" onClick="subCat(event)">Mobiliteit</li></a> <li class="subhead" value="kracht" onClick="subCat(event)">Kracht</li> <li class="subhead" value="uithouding" onClick="subCat(event)">Uithouding</li> <li class="subhead" value="stretching" onClick="subCat(event)">Stretching</li> </ul> </div>
Contains PHP files
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <?php $_POST['category'] = ''; var_dump($_POST['category']) ?>
JS file
function cat(event){ var values = $(event.target).attr('value') console.log(values); $.ajax({ url: "Videos.php", type: "post", data: { category: values }, success: function (response) { console.log('succes'); }, error: function(jqXHR, textStatus, errorThrown) { console.log(textStatus, errorThrown); } }); }
Solved the problem with the help of ADyson. (Thanks my man). I added the following code $("#showmessageID").show().HTML(result) so that the div with ID showmessageID updates every time in succession.
The div on my main PHP file (containing videos.php) receives the ID showmessageID so that it updates every time the AJAX call succeeds.
Main PHP File
JS file
Video.php