Sending multiple data parameters with jQuery AJAX

前端 未结 7 614
一个人的身影
一个人的身影 2020-11-29 22:00

I am sending an ajax request to a php file as shown here:

function checkDB(code, userid)
{

  $.ajax({
  type: \"POST\",
  url: \"

        
相关标签:
7条回答
  • 2020-11-29 22:35

    you should set your data like so :

    data: 'code='+code+'&userid='+userid
    
    0 讨论(0)
  • 2020-11-29 22:36

    The answer from Linus Gustav Larsson Thiel refers, I used the following &.ajax() that triggers when a button is clicked and it works great. I could pass day, month and year parameters.

    $('#convertbtn').on('click',function(){
    ageddajax = $("#agedd").val();
    agedmmajax = $("#agemm").val();
    ageyyyyajax = $("#ageyyyy").val();
        if(ageddajax > 0 && agemmajax > 0 && ageyyyyajax >0){
        $.ajax({
            type:'POST',
            url:'ajaxDataAge.php',
            data:'agedd_id='+ageddajax +'&agemm_id='+agemmajax +'&ageyyyy_id='+ageyyyyajax,
                success:function(html){
                $('#cydivage').html(html);
                }
            });
        }   
    });
    
    0 讨论(0)
  • 2020-11-29 22:37

    Here is how POST data should be formatted:

    key1=value1&key2=value2&key3=value3
    

    In your case (note the & as a separator):

    'code=' + code + '&userid=' + userid
    

    But jQuery does that for you if you specify your data as an object:

    data: { code: code, userid: userid }
    
    0 讨论(0)
  • 2020-11-29 22:37

    usually sending your data like this helps:

    data: { code: code, userid: userid }
    

    the most important thing to not forget is to verify if the name of the variables you are sending are the same in the server side

    0 讨论(0)
  • 2020-11-29 22:51

    you can try this :

    data: 'code='+code+'&userid='+userid,
    

    instead of

    data: 'code='+code+'userid='+userid,
    
    0 讨论(0)
  • 2020-11-29 23:00
     Try this code... 
        <script>
         function quote_ajax_table(){
           var doc_name = '<?php echo $test; ?>';
           var doc_no = '<?php echo $doc_no; ?>';
    
    $.get('quote_ajax_table.php?doc_no='+doc_no+'&doc_name='+doc_name,function(data) {
       $('.dyna').html(data);
     });
    }
    </script>
    
    //in html code 
      <div class="dyna"></div>
    
    0 讨论(0)
提交回复
热议问题