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.

    评论

报告相同问题?