jsonp callback

jsonp callback

Hi,

I have a problem with jsonp.

I create 2 channel objects and each channel uses jsonp to retrieve channel information.

Here's the code:

  1. <script>
                Channel = function(name, channelId, instanceName) {
                    this._name = name;
                    this._channelId = channelId;
                    this._instanceName = instanceName;
                   
                    $.ajax({
                        url: 'dummy',
                        dataType: 'jsonp',
                        jsonp: 'f',
                        jsonpCallback: this._instanceName + '.processData'
                    });
                }
               
                Channel.prototype.processData = function(data) {
                    console.log("person name: " + this._name);
                    console.log("channel code: " + data.playlist.channel.code);
                }
               
                one = new Channel('Channel one', 21, 'one');
                two = new Channel('Channel two', 41, 'two');
            </script>





















As you can see, in the constructor, data is being loaded (asynchronously). If I look at the network traces, I see 2 http requests, one for channel one and one for channel two:

http://dummy?f=one.processData
http://dummy?f=two.processData

In my opinion this is correct, and within the process data function, I print out the name of the object. I would expect the following:

person name: one
channel code: 21
person name: two
channel code: 41

but the following text is printed:
person name: two
channel code: 21
person name: two
channel code: 41

Can someone explain why this._name doesn't work in the jsonp callback method??? It seems that the jsonp callback method is using the instance of the last created channel object.

Thanks a lot!