This project is archived and is in readonly mode.

#300 ✓invalid
dlh

JSONP fires only first time send() is called from a periodical

Reported by dlh | April 14th, 2010 @ 07:05 AM | in 1.2.5.1

I'm trying to uses a JSONP object send() in a periodical function as abstracted below. The first time periodicRefresh() is called, the request fires and I get the expected data back. On successive calls (via the timer), the request never fires, although I see the log: "refresh:", lastSampleTime result. I assume that there's some state not reset in send().

Also inexplicable is why the onComplete function is not called, but somehow parseResponse() is. I did have to tweek sbBot.lsp to wrap output in parseResponse() to get anything back, so it sort of makes sense.

Looking a bit further, on the second call to send, it returns on:
if (!$chk(arguments[1]) && !this.check(options)) return this so something in this.check() is not happy... and then inside check() we see that this.running is false on the first call and true on successive calls. Shouldn't this be reset on success - ah onComplete is never called, so we need to look there.

OK - for not one can call cancel() before the send() and at least this part works correctly

var parseResponse = function(data){ // handle the data
// update lastSampleTime } var SB_JSONP = new Request.JSONP({

url: 'http://192.168.0.194/sb/sbBot.lsp',
data: {
    limit: 15,
    fromT: false,
    toT: null,
    fields:'Pac',
},
log: true,
onComplete: function(data){
    //this never gets called,
    log.log('got result', data);
},
onFailure: function(data){
    log.log('FAILED');
},

}); var periodicRefresh = function(){

log.log("refresh:", lastSampleTime);
    SB_JSONP.cancel() // adding this solves my problem
SB_JSONP.send({fromT: lastSampleTime, limit:10});
};

periodicRefresh()
periodicRefresh.periodical(60 * 1000); // every min

It may be that the fact that onComplete is never called is the whole problem. It also may be that I'm misunderstanding some key component regarding the callbackKey.

Actually - I'm also seeing a critical problem in that my send options are not changing those in the data{}.

Does anyony actually use this except for the demo get tweets?

Dave

I'm using mootools-1.2.4.4-more.js

Comments and changes to this ticket

  • dlh

    dlh April 14th, 2010 @ 03:59 PM

    I've done a bit more exploring here and find that this problem is resolved by having the server return the proper wrapper. IE, the server needs to look at the callback attribute in the request and wrap the json data in a function that looks like:

    Request.JSONP.request_map.request_'+ index + ( your json data )

    If this is done, then the JSONP client is happy, onComplete() runs...

    My remaining problem is that the send({ override data arguments }) do not seem to override those defined in the object creation.

    Dave

  • Arian

    Arian September 20th, 2010 @ 04:55 PM

    • Milestone set to 1.2.5.1
    • State changed from “new” to “open”
    • Assigned user set to “Arian”
    • Milestone order changed from “0” to “0”
  • Arian

    Arian September 25th, 2010 @ 12:20 PM

    • State changed from “open” to “invalid”

    This example seems to work fine here: http://jsfiddle.net/JZLwr/1/

    If you can provide a better example that shows the code is broken i'll reopen this ticket.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

The MooTools Extensions

People watching this ticket

Pages