-1

I want to join the value of field = 'city' AND '_id' string. That is to say, city_id

But I want city_id as a variable for $.post variable as below :

$.post("jquery_post",{city_id : 8},function(data){........}

Is that possible?

kalaba2003
  • 1,231
  • 3
  • 20
  • 33

1 Answers1

1

You use array notation to assign or access dynamic property names in an object.

var params = {};
params[field+"_id"] = 8;
$.post("jquery_post", params, function(data){...});
Barmar
  • 741,623
  • 53
  • 500
  • 612