1

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
OpenStack
  • 5,048
  • 9
  • 34
  • 69
  • Do you have an example of what the payload is and what the console.log output looks like? – etarhan Apr 09 '19 at 14:27
  • @LouysPatriceBessette — On a string? That won't do anything useful. – Quentin Apr 09 '19 at 14:34
  • @etarhan Updated the question – OpenStack Apr 09 '19 at 14:41
  • @Quentin: solution provided in `https://stackoverflow.com/questions/979975/how-to-get-the-value-from-the-get-parameters` does not remove all the special characters. For example white spaces gets changed to `+`, `&` remains `&`. This is not a duplicate. – OpenStack Apr 09 '19 at 15:02

0 Answers0