jQWidgets Forums

jQuery UI Widgets Forums Grid AJAX POST vs. Grid POST

Tagged: 

This topic contains 4 replies, has 3 voices, and was last updated by  Luis 4 years, 8 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • AJAX POST vs. Grid POST #56099

    mcfloyd
    Participant

    Hello,
    I am trying to have my grid get the headers and data from the same route based on a couple of keys I send through. For some reason, the grid is sending the data in a different (GET I think) format than the Ajax. Here’s some of the source:
    MY AJAX:
    $.ajax({
    type: “POST”,
    url: url,
    data: JSON.stringify(myData),
    dataType: “json”,
    contentType: “application/json; charset=utf-8”,
    complete: function(response){
    What is sent to the server (inspected in browser – request payload):
    data: “xxx”
    expansion: “xxx”
    grid: “xxx”
    module: “xxx”

    GRID AJAX:
    var mySource =
    {
    type: “POST”,
    url: url,
    data: myData,
    datatype: “json”,
    contenttype: “application/json; charset=utf-8”,
    datafields: myDatafields,
    root: “rows”,
    filterscount=0&groupscount=0&pagenum=0&pagesize=10&recordstartindex=0&recordendindex=10&module=xxx&expansion=xxx&grid=xxx&data=xxx

    If I JSON.stringify this, it ends up being garbage.
    Is there any way I can use the grid AJAX to send my POST properly?

    Thanks

    AJAX POST vs. Grid POST #56126

    Peter Stoev
    Keymaster

    Hi mcfloyd,

    If type: “POST” is set, the Grid will use POST instead of GET. If you want to format the data sent to the server, you may implement the jqxDataAdapter’s formatData callback function.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    AJAX POST vs. Grid POST #56155

    mcfloyd
    Participant

    I can’t seem to change the format of the data going to the server. When I console.log inside the formatData method, it looks like what I should be sending to the server an object with all of its properties, but then it still sends it as param1=1&param2=2&param3=3&etc…

    Any ideas how to do this?

    AJAX POST vs. Grid POST #56157

    mcfloyd
    Participant

    Ah nevermind I got it!

    I did a

    var settings = {
    formatData: function(data){
    data = JSON.stringify(data);
    return data;
    }
    }
    var myDataAdapter = new $.jqx.dataAdapter(mySource, settings);

    AJAX POST vs. Grid POST #113264

    Luis
    Participant

    Thank you mcfloyd, I was struggling a couple of days with this. Your solution worked perfectly. This one is a bit shorter:

    var dataAdapter = new $.jqx.dataAdapter(source, {
        formatData: function (data) {
            return JSON.stringify(data);
        },
    });
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.