Intercepting ajax request with decodeURIComponent resulting in special characters

16 views Asked by At

I am trying to intercept every outgoing AJAX request and log it. I am using following code.

$.ajaxSetup({
    beforeSend: function (xhr,settings) {
         console.log(decodeURIComponent(settings.data), settings.url);

    }
});

I want output in JSON format. However settings.data in this case is encoded & I am using decodeURIComponent() but even this function is not able to remove all special characters.

This is what I am trying to POST:

{
    "skip": 0,
    "Id": 4234,
    "filter": {

        "region": [
            "type = \"Global\""
        ],
        "isOrder": true,
        "list": [],

        "division": [
            "Div ONE "
        ],

        "product": [
            "Consumer"
        ],

        "period": "Current"

    },
    "orderBy": {
        "dir": "desc",
        "field": "name"
    },
    "take": 24
}

this is what my code prints on console:

skip=0&Id=4234&filter[region][]=type+=+"Global"&filter[isOrder]=true&filter[division][]=Div+ONE+&filter[product][]=Consumer&filter[period]=Current&orderBy[dir]=desc&orderBy[field]=name&take=24
0

There are 0 answers