After entering the keyword in search box, click on search icon need to get the results, everytime entering the keyword and clicking instead of refreshing the results are appending to the exisitng results, can anyone check the below where I am doing wrong.
function makeRequest()
{
$.ajax({
url:"cnc/cncstorelocator",
type:'GET',
cache:false,
data: {searchCriteria : $('#cnc-searchcriteria').val()},
dataType: 'json',
success : function(cncStoreLocatorData)
{
var store=null;
for (var i = 0; i < 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;
for (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);
}
},
error: function(cncStoreLocatorData) {
alert("can't make req");
}
});
}
@Dormilich: At function start I am making main div empty to which i am appendning the results, it’s working fine. Part from this I need one more help if my search keyword is same )Ex: I entered ‘abc’ clicked got the results again i clicked no need to call the ajax because already resluts are there so…how can I stop the ajax request at that time.