jquery - not debugging javascript code in firebug fire the error otherwise works perfectly -


i sure question seem silly many of happen me, code shared below works when debug thoroughly in firebug if not, , running code without debugging raise error,

function edit(barcode) {    $('#pnlsize').show('fast');    if ($('#test2 option').size() < 2) {      $.ajax({          url: '@url.action("selecteditemchanged")',        type: 'get',        datatype: "json",        data: {          barcode: barcode        },        success: function(sizes) {            var options = '<option value="z">سایز را انتخاب کنید</option>';          (var = 0; < sizes.length; i++) {            console.log(sizes);            options += '<option value="' + sizes[i].id + '">' + sizes[i].size + '</option>';          }          $("#test2").html(options);        }        });    }    var val = $('#test2 :selected').text();    if (val != 'سایز را انتخاب کنید' && val != null) {        location.href = '@url.action("addtocart", "shoppingcart")?barcode=' + barcode + '&size=' + $('#test2 :selected').text();;      }  }

the reason when not debug it, tries run :

 location.href = '@url.action("addtocart", "shoppingcart")?barcode=' + barcode + '&size=' + $('#test2 :selected').text();;

but dropdown has not being filled yet , user has not chosen size, addtocart return null.

please kindly me this

move code inside success function or add timer wait until success call has completed. success callback firing after rest of code runs why addtocart null.


Comments