I’m trying to make this work.
function postCharacter(id, type) {
type = type;
id = id;
var data = type + ':' + id;
$.post('', {data});
}
Hopefully from that example you can see what I’m trying to achieve. But if not, what I’m trying to do.
$.post('', {a, b});
both a and b are values that are dynamic, How can I input a dynamic data argument for the jQuery post? What I tried unfortunately did not work.
Instead of
do this
If you pass a JavaScript object jQuery will go through and put those in the request for you. In this way you can add as many dynamic values to the request without having to generate the string. If you want to add a second parameter it would look like this (where id and id2 are variables):
Also, you don’t need to have these two lines:
as they’re already set in the function arguments.