DataTables logo DataTables

via Ad Packs
Anyone able to help with doing a custom POST from editor, PLEASE
  • 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.
  • allanallan
    Posts: 15,883
    As I mention in my PM, you would use onPreSubmit to manipulate the data being set to the server:

    $(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 );
        } );
    } );
    

    Allan
  • @allan: This solution does indeed do what the OP asked for but I wonder if it is possible to go a step further and replace the entire HTTP request body with a JSON string that represents the data object. I am expecting to receive something like this ...

    {"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.
  • allanallan
    Posts: 15,883
    Hi Tim,

    Looking at the jQuery Ajax documentation it says:


    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.

    ( 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
This discussion has been closed.
← All Discussions

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Support

Get useful and friendly help straight from the source.

In this Discussion