weixin_33709364 2015-01-27 16:06 采纳率: 0%
浏览 16

设置数据标题通用ajax

  $( document ).ready(function(){

    $('.status-red').click(function(){
        var colonne_id = $('.status-red').attr('data-sort');
        data = {sort: colonne_id , '+name': $('.search-query').val()};
        console.log(data);
        $.ajax({
            url: $('.url_sortindex').val(),
            data: data,
            type: 'post',
            dataType: "json",
            success: function(data) {
                $('#body_sortindex').html(data.content);
            }
        });
    });
});

Hi, I have a search with this input.

<input type="text" value="test" placeholder="name" class="input-medium search-query form-control" name="+name" style="margin-right:5px">

But you see the name of this input name="+name". My problem is, If I create a new input named "age" for example my request ajax don't work because the name is "+name". My question is, how do you set the name for example like that

data = {sort: colonne_id , $('.search-query').attr('name'): $('.search-query').val()};

I need to get the name of my input like that $('.search-query').attr('name')

And set my title here data = {sort: colonne_id , '+name': $('.search-query').val()};

I want to set +name in data to$('.search-query').attr('name') I don't want the name in data is + name but a variable

I want to make my input generic.

Thanks you ;)

  • 写回答

1条回答 默认 最新

  • weixin_33709609 2015-01-27 16:45
    关注

    You can try this way:

    var data = {};
    
    data['sort'] = colonne_id;
    data[$('.search-query').attr('name')] = $('.search-query').val();
    

    This should work. Hope it helps.

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作