Permit a different dataFilter function depending to ajax request
It's graet that a global "dataFilter" function can be unsed for all ajax requests. But I want to run a special for some requests. Is it possible to also pass a "dataFiler" function in request options to only inpact the assiociated resquest ?
Thanks
what if the global filter gave you a URL? You could use it like this...
$.ajaxSetup({
dataFilter: function (response, type, url) {
if (url.match(/^\/api\//)) return someThingCustom(response)
return response
}
})
@paztis would that work for you if it was implemented?
The problem for me is I've got a lot of requests to manage and a lot of different dataFilters. If everything is manage in the same function, a lot of "if" will append. It's not good for the perfs...
My real problem is my responses are JSON so I specify the type to JSON. But before parsing it, I must change a IP pattern in the raw response. If I keep text response instead of JSON, I lose the simplicity of reqwest (I must parse by myself).
In jQuery, dataFilter is an option parameter for each request. It was great for me.
That's why I propose to have a global "dataFilter" function , and potentialy one "dataFilter" function in request option, like this:
reqwest({ url: 'path/to/html', method: 'post', data: { foo: 'bar', baz: 100 }, dataFilter: function(rawResponse, type) { return rawResponse.replace("{{FOO}}", "{{BAR}}"; } });
Do you see what I mean ?