JavaScript Retrieving Data with jQuery AJAX Without Reloading Page in php retrieving data with php,retrieving data with url,retrieving data

I have try to stop refresh page on click on select option but when I stop refresh page then data can not get.

here code

echo "<form name='frmtopdevotees' method='post' action='topuser_load.php'>
                <h4>select month  <select id='seldrp' name='themonth' OnChange ='document.frmtopdevotees.submit()'>     


                        $optionsmonths
                </select> 
                <select name='topdevotees' id='seldrp' OnChange ='document.frmtopdevotees.submit()'>
                        <option value=10 $M10>Top 10</option>
                        <option value=20 $M20>Top 20</option>
                        <option value=50 $M50>Top 50</option>
                        <option value=100 $M100>Top 100</option>
                </select>   </h4>               
        </form>";
?>

<script>
    $('frmtopdevotees').submit(function (e) {
        e.preventDefault();
        return false;
    });

    $('themonth').onchange(function () {
        $.ajax({
            var value = $('themonth').val();
                    type: 'post',
            data: {
                topdevotees: topdevotees,
                themonth: themonth
            },
            url: "topuser_load.php?topdevotees=" + topdevotees + "&themonth=" + themonth,
            success: function (response) {
                $('themonth').append(response);

            }
        });
    });

</script>

when I remove Onchange = 'document.frmtopdevotees.submit()' then page stop to refresh but not data change.

Answer:1

From your code what I can understand is you want to trigger a server call without refreshing the page (AJAX) whenever your any one the select option changes.

There are errors in the code posted. Following is my observation -

  1. There can be only one ID in entire page. You have used 'seldrp' in couple of places.

  2. If you want the AJAX functionality, you should avoid calling submit() function of the form.

  3. The AJAX syntax is wrong which should be as follows -

    $.ajax({
        url : "topuser_load.php?topdevotees=" + topdevotees + "&themonth=" + themonth,
        method: "post",
        data: {
            topdevotees: topdevotees,
            themonth: themonth
        }, // can even put this in variable and JSON stringify it
        success: function (response) {
            $('themonth').append(response);
    
        }
    });
    

Now coming to the solution part of it: I would do this as follows - 1. Will just listen on the select change in JQUERY 2. Once a select change is triggered, AJAX call is made and which returns the response. The modified code is -

<script>

    $('select').on('change', function (e) {
        var month = $('#seldrp1').val();
        var topdevotee = $('#seldrp2').val();

        // call ajax here -

        $.ajax({
            url: "topuser_load.php?topdevotees=" + topdevotee + "&themonth=" + month,
            method: "post",
            data : JSON.stringify({
                topdevotees: topdevotee,
                themonth: month
            }),
            success : function(response){
                $('themonth').append(response);
            },
            error : function(err){
                // handle error here
            }
        });

    });

</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
echo "<form name='frmtopdevotees'>
    <h4>select month  <select id='seldrp1' name='themonth'>

        $optionsmonths
    </select>
        <select name='topdevotees' id='seldrp2'>
            <option value=10 $M10>Top 10</option>
            <option value=20 $M20>Top 20</option>
            <option value=50 $M50>Top 50</option>
            <option value=100 $M100>Top 100</option>
        </select>   </h4>
</form>";
?>
Answer:2

This regex matches "so" when it's preceded by a comma and a space: (,\s)(so) I want to do the opposite now. I want to tell the regex: don't match "so" if it's preceded by a comma and a space. I ...

This regex matches "so" when it's preceded by a comma and a space: (,\s)(so) I want to do the opposite now. I want to tell the regex: don't match "so" if it's preceded by a comma and a space. I ...

  1. donald trump
  2. donovan mitchell
  3. donald trump twitter
  4. don toliver
  5. donuts
  6. donald trump age
  7. donatos
  8. donald glover
  9. donald trump net worth
  10. donuts near me
  11. donald trump jr
  12. donepezil
  13. don johnson
  14. donald trump speech today
  15. donna shalala
  16. donna summer
  17. donald cerrone
  18. don julio
  19. donnie darko
  20. don quixote

I tried to do this calculation with Node.js. let x = 841251657 console.log((x*x)-x) I got: 707704349563994000 printed. When I use julia I get 707704350405245649 for the same calculation. And I got ...

I tried to do this calculation with Node.js. let x = 841251657 console.log((x*x)-x) I got: 707704349563994000 printed. When I use julia I get 707704350405245649 for the same calculation. And I got ...

In many places I'm setting modified by, created by etc: const test = this.state.isValueEdited ? { modifiedById: getLoggedInUser().userId, } : { // TODO }; How could I check if getLoggedInUser has ...

In many places I'm setting modified by, created by etc: const test = this.state.isValueEdited ? { modifiedById: getLoggedInUser().userId, } : { // TODO }; How could I check if getLoggedInUser has ...

  1. conditional operator react native
  2. conditional operator react js
  3. conditional operator react
  4. conditional (ternary) operator react
  5. conditional operator in react render
  6. conditional rendering ternary operator react

I have an Array with Objects, there some of them has same "Subarrays" but with different labels. I need to summarize those based on equality. Comparing two different arrays is easy so far, but I am ...

I have an Array with Objects, there some of them has same "Subarrays" but with different labels. I need to summarize those based on equality. Comparing two different arrays is easy so far, but I am ...