javascript - How to abort ajax request -
in below code if input search vale empty , search keyword same means if entered 'abc' got result again clicked need abort ajax request, had written in beforesend method browser throwing error "cannot read property 'abort' of undefined"
ajax code:
function makerequest() { var searchtext=''; var popuprequest = $.ajax({ url:"cnc/cncstorelocator", type:'get', cache:false, data: {searchcriteria : $('#cnc-searchcriteria').val()}, datatype: 'json', beforesend: function(){ if(searchtext == '' && searchtext == searchdata) { popuprequest.abort(); } }, success : function(cncstorelocatordata) { var store=null; (var = 0; < cncstorelocatordata.length; i++) { var loc = cncstorelocatordata[i]; store = $('<div/>').addclass('pane'); var store_hours = loc.hrsofoperation; var str1 = $('<p/>').addclass('stores-timing'); var store_timings=null; (var j = 0; j < store_hours.length; j++) { var storetime = store_hours[j]; store_timings = str1.append($('<span/>').html('<strong>' + storetime.days_short)); store_timings.appendto(store); } $("#cncstorepane").append(store); searchtext=searchdata; } }, error: function(cncstorelocatordata) { alert("can't make req"); } }); }
var xhr = $.ajax({ type: "post", url: "xxx.php", data: "name=marry&location=london", success: function(msg){ alert( "the data saved: " + msg ); } }); //kill request xhr.abort()
Comments
Post a Comment