javascript - Safari double-submitting ajax calls -
i have noticed safari 5.0.5 (6533.21.1) seems submitting duplicate ajax calls. when run following reduced test case:
// jquery 1.6 include $(document).ready(function() { settimeout(function(e) { var req1 = $.getjson('/api/private/customers.json'); console.log('req1 sent'); }, 2000); settimeout(function(e) { var req2 = $.getjson('/api/private/customers.json'); console.log('req1 sent'); }, 4000); });
the safari resources panel , console show 2 xhr requests going out, server log shows 3 xhr requests coming in:
xx.xx.xx.xxx - - [10/may/2011:16:50:40 -0400] "get /api/private/customers.json http/1.1" 200 183 "https://sub.mydomain.com/customers" "mozilla/5.0 (macintosh; u; intel mac os x 10_6_7; en-us) applewebkit/533.21.1 (khtml, gecko) version/5.0.5 safari/533.21.1" xx.xx.xx.xxx - - [10/may/2011:16:50:42 -0400] "get /api/private/customers.json http/1.1" 200 183 "https://sub.mydomain.com/customers" "mozilla/5.0 (macintosh; u; intel mac os x 10_6_7; en-us) applewebkit/533.21.1 (khtml, gecko) version/5.0.5 safari/533.21.1" xx.xx.xx.xxx - - [10/may/2011:16:50:42 -0400] "get /api/private/customers.json http/1.1" 200 183 "https://sub.mycomain.com/customers" "mozilla/5.0 (macintosh; u; intel mac os x 10_6_7; en-us) applewebkit/533.21.1 (khtml, gecko) version/5.0.5 safari/533.21.1"
when make same request latest version of firefox, correctly 2 requests:
xx.xx.xx.xxx - - [10/may/2011:16:52:00 -0400] "get /api/private/customers.json http/1.1" 200 183 "https://sub.mycomain.com/customers" "mozilla/5.0 (macintosh; intel mac os x 10.6; rv:2.0.1) gecko/20100101 firefox/4.0.1" xx.xx.xx.xxx - - [10/may/2011:16:52:02 -0400] "get /api/private/customers.json http/1.1" 200 183 "https://sub.mycomain.com/customers" "mozilla/5.0 (macintosh; intel mac os x 10.6; rv:2.0.1) gecko/20100101 firefox/4.0.1"
this behavior not seem happen on first request, subsequent requests sent in duplicate. have idea going on? efforts detect requests in js futile.
i believe browser making conditional request second call (also see 304 response status).
on first call there no cached response in browser, normal request.
on second request browser first conditional request, , upon seeing cached response out of date has repeat request.
as far know jquery has builtin fix (it automatically appends parameter request url, _=123456789
). don't know why not working here.
you try append request param hand this: '/api/private/customers.json?v='+(new date().gettime())
or try , use jquery.ajax
cache:false
, , datatype:'jsonp'
you can open safari's developer tools (web inspector), , check network tab. tell more request , response.
Comments
Post a Comment