ajax url or post data while uploading
ajax url or post data while uploading
Hi all,
I have an child editor in a parent-child solution, that I use to add documents to my employees. I need to add the foreign id of the employee to the document table, but I need that data also while uploading the file. I tried several ways. Below you find te latest not working solution. As you can see, I tried to use a function to build up the url dynamically. But this results in adding the function to the ajaxurl and this eventually results in a 404 of course.
I've also tried to add a regular variable to the url ( url: 'datatables/php/table.document.php?foreign_id='+key and changing the variable when a row is selected in the parent (employee) table, but the url always sends the initial value of the variable.
var documenteditor = new $.fn.dataTable.Editor( {
ajax: {
url: function ( u ) {
var selected = employeetable.row( { selected: true } );
if ( selected.any() ) {
return 'datatables/php/table.document.php?foreign_id='+selected.data().employee_id;
}
},
data: function ( d ) {
var selected = employeetable.row( { selected: true } );
if ( selected.any() ) {
d.foreign_id = selected.data().employee_id;
}
}
},
Does anyone have a clue?
Kind regadrs,
nessinits
Replies
Your url is in an if statement. If it evaluates false, the url will be undefinded.
Your data section does not return anything but undefined since it does not return anything.
And you don't need both a url with the parameters attached and a data that also returns parameters.
Hi,
Thanks for your response.
It doesn't evaluate false, because it can only be posted when an emloyee is selected.
I don't understand your emark on the data section. Mainly the part where you say: since it does not return anything. Could you be more specific why?
I tried both ways because of I want to resolve this one way or the other. The data way is the cleanest, of course.
Hope you can help me a little more.
Kind regards,
nessinits
That function does not return anything, as @bindrid says.
How is that different from the example from the website below:
That statement wasn't quite accurate - although I completely concur with the point about the url being undefined. It should at least point at an error script I would say.
The way the
ajax.data
option works as a function is that you can modify the object passed in and that will be used. Alternatively, you can return an object and DataTables / Editor will use that instead. Both are valid.I don't think you can define the URL as a function in jQuery and that isn't a feature that DataTables adds.
This with the
upload
field type is it? You can give it its ownajax
option that submit parameters specifically for that. However, theajax.data
function should be used. Could you give me a link to the page please?Allan