0

I just wanted to keep an "Ajax Log" on my application. What do I mean? Having a way to store all the "Internal Server Error" of AJAX requests.
Plus, having to change all the $.ajax calls would not be useful (if I change the storage system or the error type etc... I shall change all occurences).

So that's what I've got for now :
I made a global AJAX Event function simply with that instruction : $(document).ajaxError(sendErrorAjax);
And that's what my sendErrorAjax function might look like :

function sendErrorAjax( event, response, settings )
{
    let message = 'Error on URL [' + settings.url + '] - Error ' + response.status + ' : ' + response.statusText;
    addToLogs(message);
}

And that works fine! But I'd like to have more precise informations : What about retreiving the data that was sent (client side, not the server side)?

Is there any way to get them?

Marco
  • 196
  • 1
  • 1
  • 12
  • 1
    Isn't it in `settings.data`? – Barmar Aug 31 '18 at 10:39
  • Oh... Yeah, that's a good answer in most cases (POST, PUT, DELETE, etc...). Just realise I was using a GET method. So I have to parse the URL in my case. In other cases, we can access them by the `settings.data` property, yes. So in either case, we get a string with all parameters [that we can then parse to JSON](https://stackoverflow.com/a/8486188/9863298). – Marco Aug 31 '18 at 11:01

0 Answers0