How to pass multiple variables to PHP with jQuery

后端 未结 1 1196
攒了一身酷
攒了一身酷 2020-12-12 05:12

Ok guys hope you can help me with this one as well. I am not to crazy knowledgeable with jQuery and AJAX and probably I am missing something very simple. I am not able to pa

相关标签:
1条回答
  • 2020-12-12 05:44

    POST AJAX REQUEST using JS / JQUERY. The below is the syntax I use for all my AJAX calls.

    var first = 'something';
    var second = 'second';
    var third = $("#some_input_on_your_page").val();
    
    
    ///////// AJAX //////// AJAX //////////
        $.ajax({
            type: 'POST',
            url:  'page_that_receives_post_variables.php',
            data: {first:first, second:second, third:third},
            success: function( response ){
                alert('yay ajax is done.');
                $('#edit_box').html(response);//this is where you populate your response
            }//close succss params
        });//close ajax
    ///////// AJAX //////// AJAX //////////
    

    Code for the PHP page page_that_receives_post_variables.php

    <?php
    $first = $_POST['first'];
    $second = $_POST['second'];
    $third = $_POST['third'];
    
    echo 'now do something with the posted items.';
    echo $first; //etc...
    ?>
    
    0 讨论(0)
提交回复
热议问题