jquery - Is it possible to specify context in callback of a jsonp Ajax call? -


is possible specify our specific context in callback of jsonp ajax call?

the way found specifying callback name not implementing callback go in success method desired context:

    $.ajax({         type: "get",         url: 'someurl',         datatype: 'jsonp',         jsonpcallback: 'mycallbackname',         context: this,         success: function (response) {                    console.log(this); //this must context specified earlier         }     }); 

the problem if it's working, receive lot of errors:

typeerror: mycallbackname not function

any idea of how achieve without causing errors?

thanks

etienne

this should trick:

$.ajax({     type: "get",     url: 'someurl',     datatype: 'jsonp',     jsonpcallback: 'mycallbackname',     context: this,     success: delegate(this, function (response) {         console.log(this); //this must context specified earlier     }) });  var delegate = function(context, func) {     return function() {         return func.apply(context, arguments);     } } 

however, typeerror: mycallbackname not function because don't have mycallbackname defined. add

var mycallbackname  = function() { } 

p.s. more delegation in javascript here.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -