Simplest way to post-process the result of a jQuery ajax request?
-
29-10-2019 - |
سؤال
Suppose I have a function fancyParse
intended to take the response returned by the server and turn it into something else. This function throws if the response makes no sense whatsoever, or if it has a special "internal error" flag set.
I'd like to chain this function into a $.post
call to get a new Deferred
. This new deferred would fail if the request fails, or if fancyParse
throws. It would succeed if the request succeeds and fancyParse
succeeds, and, importantly, will pass the result of fancyParse
to its success callbacks.
The perfect solution would look something like this:
$.post('/url', etc).postprocess(fancyParse)
.done(my_done_handler)
.fail(my_fail_handler);
Is something like this already available, or do I need to write such a postprocess
myself?
لا يوجد حل صحيح
لا تنتمي إلى StackOverflow