Pergunta

I am trying to intercept an ajax jsonp response to do some response filtering. My guess was, I could do this with custom converters. But the converter function is never run. What am I missing?

var ajax_options = {
    dataType: 'jsonp',
    jsonp: 'callback',
    url: url,
    data: parameters,
    success: success,
    converters: {
        "jsonp": function (raw) {
            console.log(raw);
            return raw;
        }
    }
};
$.ajax(ajax_options);

Thanks, McFarlane

Foi útil?

Solução

I've now listened to common sense and decided to not misuse the poor converters. I've created a solution using $.proxy() to intercept every JSONP response while keeping the correct context in the callback function.

Because my solution heavily depends on jQueryMX I won't paste my source here.

Outras dicas

From the docs, converters are:

A map of dataType-to-dataType converters. Each converter's value is a function that returns the transformed value of the response.

Hence it's used to convert from one dataType to another.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top