This project is archived and is in readonly mode.

#300 ✓invalid

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

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

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: '',
data: {
    limit: 15,
    fromT: false,
    toT: null,
log: true,
onComplete: function(data){
    //this never gets called,
    log.log('got result', data);
onFailure: function(data){

}); var periodicRefresh = function(){

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

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?


I'm using mootools-

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.


  • Arian

    Arian September 20th, 2010 @ 04:55 PM

    • Milestone set to
    • 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:

    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