javascript - Safari and IE ajax issues with subsequent calls (.then) -
i've got code:
var request1 = this.add(prod_id, pack_id_combination, button, pack_qty).then(function(rdata1){ // works this.add(prod_id, case_id_combination, button, case_qty).then(function(rdata2){ // (random) doesn't work }.bind(this), function(req, status, error){ console.log('case error',req, status, error); }); }.bind(this), function(){ console.log('pack error'); });
i omitted rest of code because it's huge class , it's impossible build jsfiddle, things.
but here's facts:
my js points php file returning data. ajax calls via
add()
function (see below)it works first call, doesn't work second call.
on log, status = 'error', error = '' (empty, no info here)
i know sure second add(), if called alone same params, work.
furthermore, has these problems in safari , ie, not in chrome, ff, android
furthermore, has these problems if tested online, while in local environment works properly.
safari says looses connection. information can get
the add()
function quite trivial:
add:function(idproduct, idcombination, callerelement, quantity){ return $.ajax({ type: 'post' ,headers: { "cache-control": "no-cache" } ,url: baseuri + '?rand=' + new date().gettime() ,cache: false ,datatype : "json" ,data: 'controller=cart&add=1&ajax=true&qty=' + ((quantity && quantity != null) ? quantity : '1') + '&id_product=' + idproduct + '&token=' + static_token + ( (parseint(idcombination) && idcombination != null) ? '&ipa=' + parseint(idcombination): '') ,success:function(data, status, req){ console.log('ok'); } ,error:function(jqxhr, textstatus, errorthrown){ console.log(jqxhr.responsetext, textstatus, errorthrown); } }); },//end add()
so, question: there way avoid problem? common pitfall? there common practices avoid kind of issues?
ok, issue solved using get request instead of post one.
probably both safari , ie not able correctly manage 2 subsequent ajax post requests, @ least in specific circumstances. or, jquery 2.1.3 (version used here) implementation has kind of subtle problems/bugs.
but since have random css/js issues both ie (surprise...) , safari (yes...), guess it's them , not jquery.
Comments
Post a Comment