Custom Ajax function not receiving parameters
Custom Ajax function not receiving parameters

When I used the DataTables Editor custom ajax call, the only parameter that wasn't undefined was data. Why isn't method "POST" when creating a new row in Editor?
d = JSON.parse(JSON.stringify(data));
let { cust_id, username, password, account_type_id} = d.data[0];
data = {
username,
password,
account_type_id
};
if(method === "POST"){
url = `${_config.apis.dti1ticketapps.credentials1ticket}/${cust_id}`
} else {
url = `${_config.apis.dti1ticketapps.credentials1ticket}/${cust_id}/${account_type_id}`
}
$.ajax( {
type: method,
url: url,
...(method !== 'DELETE' && {data}),
headers: { 'x-api-key': _config.apis.dti1ticketapps.token},
dataType: "json",
success: function (json) {
success( json );
},
error: function (xhr, error, thrown) {
error( xhr, error, thrown );
}
} );
};
Window.systemsManager.editor = editor = new $.fn.dataTable.Editor({
dom: "Bfrtip",
idSrc: 'cust_account_id',
ajax: credentialsFunc,
table: "#transferTable",
fields: [
{
label: "Id",
name: "cust_account_id",
type: "hidden"
},
{
label: "Type",
name: "account_type_id",
type: "select2"
},
{
label: "Username",
name: "username"
},
{
label: "Password",
name: "password"
},
{
label: "Location",
name: "account_location"
}
]
});
This discussion has been closed.
Answers
I'm sort of assuming that the code from lines 1 to 29 is the
credentialsFunc
function. Is that correct? If so, it isn't using POST because you haven't got that in your$.ajax
call. Addtype: 'POST'
to the list of options. jQuery defaults to GET.Without the
credentialsFunc
line showing me the parameters you define and use, I can't really say much more than that.Allan