Anyone able to help with doing a custom POST from editor, PLEASE
Anyone able to help with doing a custom POST from editor, PLEASE
danieljamesbertrand
Posts: 8Questions: 0Answers: 0
Hi,
I need someone to explain to me how to prevent editor from submitting an ajax request to a URL with it's own variables (I don't want action=edit in the PUT)
I only want my own d={"a" : 1, "b" : 2, "c" : "cow"}
something like this but I am not sure....
editor = new $.fn.dataTable.Editor( {
"ajaxUrl": "",
"domTable": "#usrTbl", <--- my data is in HTML table "usrTbl"
"fields": myFields, <--- myFields were set up for editor
"events" : {
"onPreSubmit": function (oData) {
var MYJSON = JSON.stringify(oData);
$.ajax({
"dataType": 'json',
"type": "PUT" ,
"url": baseURL + getAccountString + "?d={MYJSON}";
});
}
}
} );
Thanks in advance.
I need someone to explain to me how to prevent editor from submitting an ajax request to a URL with it's own variables (I don't want action=edit in the PUT)
I only want my own d={"a" : 1, "b" : 2, "c" : "cow"}
something like this but I am not sure....
editor = new $.fn.dataTable.Editor( {
"ajaxUrl": "",
"domTable": "#usrTbl", <--- my data is in HTML table "usrTbl"
"fields": myFields, <--- myFields were set up for editor
"events" : {
"onPreSubmit": function (oData) {
var MYJSON = JSON.stringify(oData);
$.ajax({
"dataType": 'json',
"type": "PUT" ,
"url": baseURL + getAccountString + "?d={MYJSON}";
});
}
}
} );
Thanks in advance.
This discussion has been closed.
Replies
[code]
$(document).ready(function() {
var editor = new $.fn.dataTable.Editor( {
"ajaxUrl": "php/browsers.php",
...
} );
editor.on('onPreSubmit', function ( e, data ) {
delete data.action;
data.d = JSON.stringify( data );
} );
} );
[/code]
Allan
{"action": "create", "id": null, "table": null, "data": {"name": "My Name", "value": "My Value"}}
I tried the following in the onPreSubmit event ...
data = JSON.stringify( data );
... but it seems that the data object is subsequently re-evaluated when creating the HTTP request body. Is there anyway to bypass or disable this?
Thanks.
Looking at the jQuery Ajax documentation it says:
[quote]
processData:
By default, data passed in to the data option as an object (technically, anything other than a string) will be processed and transformed into a query string, fitting to the default content-type "application/x-www-form-urlencoded". If you want to send a DOMDocument, or other non-processed data, set this option to false.
[/quote]
( http://api.jquery.com/jQuery.ajax/ )
So I think this is what you are looking for.
The $.ajax call that Editor makes can be overridden with Editor's 'ajax' initialisation option: http://editor.datatables.net/options/#ajax .
Regards,
Allan