简体   繁体   中英

Using $.post with jQuery and php

I'm have a problem with POST in my php script:

`echo` "<script type='text/javascript'>
    //<![DATA[
    $(document).ready(function()
    {
        $('.activiteit_vrij').change(function()
        {
            `var` idv=$(this).val();
            `var` dataString = 'idv='+ idv;
            $.ajax
            ({
                `type`: 'POST',
                `url`: 'ajax/activiteit_vrij_selectie.php',
                `data`: dataString,
                `cache`: false,
                `success`: function(html) { $('.activiteit').html(html); } 
            });
        });
    });
    //]]>
    </script>";

In ajax/activiteit_vrij_selectie.php I pickup the value with: $overdracht = \ $_POST`['idv'];`

It responds with:

jquery-3.1.0.min.js:4 POST /taakbeheer/ajax/activiteit_vrij_selectie.php 500

I cannot find any answer about error 500 In the past it was working fine. Usin jQuery jquery-3.6.0.min.js

I think I need to use jQuery.post( url [, data ] [, success ] [, dataType ] ) or is it another issue. Tried to find any sl

Please try this instead. There is no need to echo and the backticks are weird

?>
<script>
$(function() {
  $('.activiteit_vrij').on("change", function() {
    const data = { "idv": $(this).val()}
    $.post('ajax/activiteit_vrij_selectie.php',data, function(html) {
        $('.activiteit').html(html);
    });
  });
});
</script>
<? .....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM