EasyUI Forum

General Category => General Discussion => Topic started by: Silas on April 27, 2016, 02:09:00 AM



Title: Request: eDatadrip posting json data
Post by: Silas on April 27, 2016, 02:09:00 AM
Hello,

I'm using eDatagrid with json backend. When I use save, delete or create urls, the data is posted in form-data format.

Is there a way to post json data since that's the format the data is delivered to the grid?

I do not want to handle two different data-formats on my backend and have not found a solution to convert form data to json.

Best regards,
Jan


Title: Re: Request: eDatadrip posting json data
Post by: stworthy on April 27, 2016, 07:41:38 PM
You can custom the post method by overriding the 'poster' function. Be sure to download the newest 'jquery.edatagrid.js' file from http://www.jeasyui.com/extension/edatagrid.php
Code:
$('#dg').edatagrid({
    poster: function(url, data, success, error){
        $.ajax({
            type: 'post',
            url: url,
            data: data,  // JSON.stringify(data)
            dataType: 'json',
            success: function(data){
                success(data);
            },
            error: function(jqXHR, textStatus, errorThrown){
                error({
                    jqXHR: jqXHR,
                    textStatus: textStatus,
                    errorThrown: errorThrown
                });
            }
        });
    }
});