superagent-jsonp icon indicating copy to clipboard operation
superagent-jsonp copied to clipboard

Uncaught ReferenceError: callbackName is not defined

Open 332065255 opened this issue 6 years ago • 4 comments

经常会出这个问题,偶现性

332065255 avatar Apr 03 '18 09:04 332065255

Could you please provide more information about this issue?

E.g. Browser / code example

marcalexiei avatar Apr 04 '18 16:04 marcalexiei

Maybe are you sending multiple call at once with the same callbackName?

superagent.get('exampleURL')
      .use(superagentJSONP({ callbackParam: 'jsonp', callbackName: 'myCallbackName', timeout: 10000 }))
      .end(function(err, res){
        console.info(err, res)
      });

superagent.get('exampleURL')
      .use(superagentJSONP({ callbackParam: 'jsonp', callbackName: 'myCallbackName', timeout: 10000 }))
      .end(function(err, res){
        console.info(err, res)
      });

superagent.get('exampleURL')
      .use(superagentJSONP({ callbackParam: 'jsonp', callbackName: 'myCallbackName', timeout: 10000 }))
      .end(function(err, res){
        console.info(err, res)
      });

The plugin cancel callbackName window function after the request is ended. If you use the same name on parallel calls only the first call will found the function stored in window.

marcalexiei avatar Apr 04 '18 16:04 marcalexiei

I had the same issue, specifying the timeout worked me. The callback is being removed from window before it is called. Specifying the timeout option wasn't necessary in the prior version I was using. For a baseline, the response times range from 60ms to 150ms in my use case.

jamesakers avatar May 09 '18 17:05 jamesakers

I had the same issue, providing .use(jsonp({timeout: 10000})) solved the issue. Thanks.

ceremcem avatar Jun 15 '18 02:06 ceremcem