Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.

trying to use timer id for ajax in listener its not working

Avatar

Level 2

IN one of my dialog listener i m using ajax call where I wanted to give some timer which is not working 

what's that I m writing wrong in here. Can anyone please help me here..

 

Here is the code in my listener

function(dialog){
var path = dialog.path;
var pagePath = path.substring(0,path.indexOf("/jcr:content") + 12);
var country= this.getField("./country").getValue();
var state= this.getField("./state").getValue();
var district= this.getField("./district").getValue();
var targetUrl= this.getField("./target").getValue();
var availability= this.getField("./availability").getValue();
var showonmarketing = this.getField("./showonmarketing").getValue();
var mobileurl = this.getField("./mobileurl").getValue();
var latitude = 0;var longitude = 0;
if (pagePath){
var jcrPath = pagePath.substring(0,pagePath.indexOf("/jcr:content") + 12) + "/location" + "/" + country + "/" + state + "/" + district;
alert("BEFORE TIMERID");
alertTimerId = setTimeout(function () {
alert("after TIMERID started ");
jQuery.ajax({
url: "http://dev.virtualearth.net/REST/v1/Locations",
dataType: "jsonp",
data: {
key: "Akg_FZYIXiJc8S0ZecryN60DVoNKcHsd8fNm89pSSshPe_R4y89aoVQB8tBK02zt",
CountryRegion: country,adminDistrict: state, locality: district, output:"json"
},
jsonp: "jsonp",success: function (data) {
alert("after ajax success ");
var result = data.resourceSets[0];
if (result) {
if (result.estimatedTotal > 0) {
var coord = result.resources[0].point.coordinates;
latitude = coord[0];
longitude = coord[1];
alert("after TIMERID started inside ajax");
setLatLong(latitude,longitude,targetUrl,mobileurl,availability,jcrPath,district,showonmarketing);
alert("after setting latlong ");
}
}
},
error : function (xhr, ajaxOptions, thrownError,) {
alert("AJAX call from bing got failed");
}
});
}, 2000);

}
}

function setLatLong(latitude,longitude,targetUrl,mobileurl,availability,jcrPath,district,showonmarketing) {
CQ.Ext.Ajax.request({
url : jcrPath,
headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
params : {
url : targetUrl,
mobileurl: mobileurl,
availability : availability,
latitude : latitude,
longitude : longitude,
showonmarketing : showonmarketing,
},
success: function(objServerResponse){
console.log(objServerResponse);
alert(objServerResponse);
alert("The city you entered is Inserted");
},
failure : function(objServerResponse){
alert("error: The city is not Inserted properly, Please reenter it again");
}
});
}

0 Replies