dtpf76658 2015-05-08 22:11
浏览 190
已采纳

发送带有serialize()函数的表单和ajax()中的额外数据

I'm programming a web page for a company in CI3, and I've another problem. I need to send to wizard.php(controller)a serialized form and a javascript variable, but, I think that I can't send 2 variables at the same time, here is my code.

var idCompany =5;
$(document).on('submit', '#period-form', function(event) {
    event.preventDefault();
    $.ajax({
        url: '<?php echo base_url()?>wizard/insertPeriod/'
        type: 'POST',
        dataType: 'json',
        data: $("#period-form").serialize(),
        success : function (json) {
            $("#alert").append(json.response_alert);
        },
        error : function (xhre) {
            console.log(xhre);
        }
    })
});

As you can see, idCompany is an attribute, it has value but, I put value in another function. is possible add values to a serialized form? or how I can send a serialized form and a variable at the same time?

  • 写回答

2条回答 默认 最新

  • duanjie1339 2015-05-08 22:14
    关注

    The serialize function simply creates an URL query string from all the form elements. So you can manually add the variable to the result of the serialize() function like this:

     data: $("#period-form").serialize() + '&idCompany=' + idCompany
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥15 在现有系统基础上增加功能