Closed GoogleCodeExporter closed 8 years ago
Very weird. Do you have a complete example somewhere? I'm wondering if we're
not lacking some crucial context in here.
Original comment by aubourg.julian
on 7 Jul 2010 at 7:38
Hi Julian,
Thanks for looking into this. I admit this sure seems weird. It all seems to
do with the fact that we decided to name our callback the same value as the
name of this misbehaving function (cut and paste thing for automated tests).
If we remove the callback and use the default or rename the callback to
anything else, it works fine. I'll attach a test but its located here
http://indusdemo.induscorp.com/jsonp_test1.html
Indeed, I can show the same thing using the alert function!
http://indusdemo.induscorp.com/jsonp_test2.html
function TestCase1() {
jQuery.jsonp({
"cache" : "true",
"callback" : "alert",
"callbackParameter" : "optJSONPCallback",
"complete" : function(xOptions, textStatus) {
alert('complete');
},
"data" : {"pFullText" : "Dyer Lake", "optOutPrettyPrint" : 0},
"error" : function(XMLHttpRequest, textStatus) {
alert('error');
},
"success" : function(json) {
alert('SUCCESS but alert no work!');
},
"url" : "http://epadev.induscorp.com/waters10/WATERS_SERVICES.NameService"
});
}
Hope that makes it clear. Thanks again for the attention. Your product is
great. Its in use (version 1.1.4) by the EPA here if you want to add to your
list of users:
http://www.epa.gov/waters/tools/WATERSServicesJSLib/WATERSServicesJSLib.html
Cheers,
Paul
Original comment by pauldzie...@gmail.com
on 7 Jul 2010 at 12:53
Attachments:
Oh, of course! Never ever use the name of an existing function as a callback
name: version 2.x redefines the function since it has to seeing as it doesn't
work into an iframe anymore. It's not that the function is not called, it's
that you call jquery-jsonp's internal generic callback instead.
Original comment by aubourg.julian
on 7 Jul 2010 at 1:21
I added the information in the doc for the callback parameter. No way you can
just change the callback name so that there are no more collisions? For
instance, do you really need to change the default?
Original comment by aubourg.julian
on 7 Jul 2010 at 1:36
Hi Julian,
Thanks for the quick response. For the generic wrapper we have written around
these calls, we planned for the possibility of asynchronous usage. If slow
call A fires first using default callback _jqjsp and then speedy call B fires
using the same _jqjsp callback, won't B's callback overwrite A so that when A
finally returns it ends up executing B's function? I haven't tested this but
you do mention in your new wiki comment that all this happens in the global
scope.
So I think the answer is that any callbacks need to be unique amongst
themselves and they need to be named such that they do not conflict with
anything else that happens to be in the global scope? My first thought is to
write some kind of generator to create unique callbacks - _jqjsp + random
number + running sequence? Is that something we could recommend as an
enhancement?
Thanks,
Paul
Original comment by pauldzie...@gmail.com
on 7 Jul 2010 at 4:06
You can have as many concurrent requests as you want with the same callback and
it will work as expected.
There was an issue in IE
(http://code.google.com/p/jquery-jsonp/issues/detail?id=21) but I had a backup
solution for the browser anyway as I suspected there could be a problem (I
mean, it's IE, right?).
So, to make things clear, you can have as many requests running concurrently as
you want to, with the same callback name, without any known response order and
everything will be called as it should.
That was the behaviour in 1.x and was a mandatory feature for any
non-iframe-based solution... which includes 2.x ;)
Original comment by aubourg.julian
on 7 Jul 2010 at 10:58
Original issue reported on code.google.com by
pauldzie...@gmail.com
on 6 Jul 2010 at 5:05