If you want to use a variable sent back by an Ajax request, how can you make the function "wait for it"...
in the code below, there are 2 console.log(pdfurl)... one inside the ajax and one outside... the outside seems to run before the one inside the ajax.. so my code that needs to use that variable doesn't work... I really don't want to put the other code inside the Ajax request.. any suggestions?
for example:
in the code below, there are 2 console.log(pdfurl)... one inside the ajax and one outside... the outside seems to run before the one inside the ajax.. so my code that needs to use that variable doesn't work... I really don't want to put the other code inside the Ajax request.. any suggestions?
for example:
Code:
onDoubleClickThumbnail: function(view, rec, item, index, e, eopts) { var clid = rec.get('CLNUMBER'); var bkid = rec.get('BKID'); var pgid = rec.get('PGID'); var imgpath = rec.get('PGPATH'); var pdfurl; var me = this; Ext.Ajax.request({ url: 'vvcall.pgm', params: { pgm: 'mcb002r', action: 'showpdf', clid: clid, bkid: bkid, pgid: pgid, imgpath: imgpath }, scope: me, success: function(response) { var d = Ext.decode(response.responseText); if (d.SUCCESS === '1') { pdfurl = '/cache/' + d.PDFDOC; console.log(pdfurl); //<-works.... } else { alert('error'); } } }); console.log(pdfurl); //<--returns undefined...
Comment