user_777
user_777

Reputation: 805

pass multiple datas in to the ajax

Here for sending multiple values to the ajax i had done my code like this please have a look

$("#btnSubmit").on("click", function (e) {
    e.preventDefault();
    var toPost = $('.row_selected input').serialize();
    var form_data={      
                    date: $('#transfer_date').val(),
                    group: $('#lo_group').val(),
                    name: $('#name').val(),
                    phone: $('#phone').val(),
                    location: $('#loc_id').val()

                  }
    $.ajax({
    type: 'POST',
    url: '<?php echo base_url();?>admin_control/transfer_tool/<?php echo $result->id;?>',
    data: 'toPost='+toPost+'&form_data='+form_data,
    cache: false,
    dataType:"json",


 });

});

Here only first value is getting and the second value is not passing,tried a lot but couldn't find a solution.please help me to solve

Upvotes: 1

Views: 29

Answers (1)

Pirai Sudie
Pirai Sudie

Reputation: 172

Convert javascript object to data parameters

use jQuery.param(form_data)

    $.ajax({
    type: 'POST',
    url: 'www.test.com/admin_control/transfer_tool/',
    data: 'toPost='+toPost+'&form_data='+jQuery.param(form_data),
    cache: false,
    dataType:"json",


 });

Upvotes: 2

Related Questions