I have a javascript function with jQuery that calls an API. A part of the call sets the object type, and sets it to the object id. The right function is set, but I do not know how to set the key correctly. The API get "object_type" and not "itemDetails" for the parameter in data.
Is there a way to set the value of a key in the data array to itemDetails as its called from the function?
function details_api(object_id, object_type){
$.ajax({
url: '/api.php',
type: 'POST',
data: {
function: object_type,
data: {
object_type: object_id
}
},
error: function() {
alert('An error occurred connecting to server. Please check your network');
},
dataType: 'json',
success: function(json) {
if (json.status) {
console.log(json.data);
}else{
alert(json.message);
}
}
});
}
details_api('1', 'itemDetails');