weixin_33698823 2017-12-26 09:12 采纳率: 0%
浏览 56

通过ajax传递数组

When I click to button: -Iterate all tr and collect all its input's name to a array(this has been done) -I also get data from two text which names are input and trigger -Send all of them(one array and two text) via ajax to asp.net.cs(not working)

    var senders = [];
    $("#btn_input_kaydet").click(function () {

        var input = $("#dd_input").text();
        var trigger = $("#dd_input_trigger").text();


        $("#dynamic_input_field tr").each(function (i) {
            senders[i] = $(this).find('td input').attr('name'); 
        });



        $.ajax({
            type: "POST",
            url: "senaryo.aspx/addscnerio",
            data: { "arr": senders, "input": input, "trigger": trigger},
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                alert("successful")
            },
            traditional : true
        });

    });



    [WebMethod]
    public static void addscnerio(List<String> values, string name, string trigger)
    {

    }
  • 写回答

5条回答 默认 最新

  • YaoRaoLov 2017-12-26 09:22
    关注

    Assuming the id of your table = dynamic_input_field you can do the following

    var senders= [];
    var headers = [];
    $('#dynamic_input_field th').each(function(index, item) {
        headers[index] = $(item).html();
    });
    $("#dynamic_input_field tr").has('td').each(function() {
        var arrayItem = {};
        $('td', $(this)).each(function(index, item) {
            arrayItem[headers[index]] = $(item).html();
        });
        senders.push(arrayItem);
    });
    

    then send senders in your ajax

    评论

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容