the_best
the_best

Reputation: 77

send multiple data with $.ajax() jquery using selectors as well

is there a way to send data with ajax mixing selector and independent data like this:

$.ajax({
    url:"here.php",
    data: $("#form :input")+"&"+"id="+id,
    type:"POST",
    success: function(res){
        $("#something").html(res);
    }
})

I know I can send data with either one of them alone, but it would help me so much to know if this is possible. Any help and recommendations will be appreciated.

Upvotes: 1

Views: 470

Answers (2)

Kevin B
Kevin B

Reputation: 95047

You don't want to send a selector, you want to send the value of inputs within the form.

var data = $("#form").serialize();
data += "&id=" + id;
$.ajax({
    url: "foo.php",
    data: data,
    ...
});

Upvotes: 1

Adil Shaikh
Adil Shaikh

Reputation: 44740

you can use serialize() (i suppose you are trying to send all input values inside your #form)

 data: $("#form :input").serialize() + "&" + "id=" + id,

Upvotes: 5

Related Questions