javascript - neither success nor error is working in jquery ajax -
i beginner jquery ajax. below ajax code working fine when using async: false
, due problems in firefox removed after referring link(i facing same issue). not working. not showing errors.
here code:
try { _ajaxcall = $.ajax({ url: url, type: "post", data: "drqlfragment=" + text, //async : false, cache: false, headers: { accept: "application/json", contenttype: "application/x-www-form-urlencoded" }, contenttype: "application/x-www-form-urlencoded", //processdata : true, success: function (data, textstatus, jqxhr) { var resdata = data.suggestions; (var = 0; < resdata.length; i++) { sugdata.push(resdata[i].keyword); } }, error: function (response) { //error here alert('hello'); } }); } catch (e) { alert(e); }
the above code neither executing success
nor error
. tried catch error keeping try catch
block no use.
the problem was doing manipulations outside success callback function. working fine when used async: false
. means ajax call synchronous. when removed async: false
, manipulations doing outside success callback function not working. problem because of asynchronous behaviour of ajax call. when calling ajax call asynchronously, not flow code priciple i.e step step , top bottom can happen anytime. so, not able desired output.
when replaced code manipulations in success callback, code working fine. @mccannf pointed problem in above comments. :).
Comments
Post a Comment