user4336343
user4336343

Reputation:

Pass variable and form.serialise array to controller

I am using AJAX to pass form data to controller, that can be done easily, But i along with form.serialise array, i want to pass one additional variable value as well,

I tried with below code, I could able to print ID value in console.log but when form data send to controller, ID is pass as string id, not number,

How can i pass variable value?

  event.preventDefault();
            var pathArray = window.location.pathname.split( '/' );
            var id = pathArray[6];
            console.log(id);

            $("#LoadingImage").show();
                $.ajax({
                    type: "POST",
                    url: "<?php echo base_url(); ?>index.php/user/expensecenter/add_expense",
                    data: $("#expense_common").serialize() + "&report_id=id",

I want to pass value 13(this is number in url) to as report_id, how can i do that?

Upvotes: 0

Views: 46

Answers (2)

Norlihazmey Ghazali
Norlihazmey Ghazali

Reputation: 9060

To ensure sending the integer value, use this:

data: $("#expense_common").serialize() + "&report_id=" + parseInt(id),

Upvotes: 0

Yuriy Novikov
Yuriy Novikov

Reputation: 321

data: $("#expense_common").serialize() + "&report_id=" + id,

Upvotes: 1

Related Questions