PHP AJAX not updating dynamically even though consolelog has correct value
P粉550257856
P粉550257856 2024-04-02 17:50:59
0
1
405

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);
        }
    });
}

P粉550257856
P粉550257856

reply all(1)
P粉136356287

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

$.ajax({
    url: "http://localhost/exercise/Videos.php",
    type: "post",
    data: { category: category_SQL },
    success: function (data) {
        $("#showmessageID").show().html(data)
    },
    error: function(jqXHR, textStatus, errorThrown) {
        console.log(textStatus, errorThrown);
    }
});

Video.php

echo $_POST['category']
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!