Pass variable from get into ajax
I'm trying to check if a file exists and if it does set a variable (furl) to a string and if it doesn't to another string.
Furl isn't being found after the get runs. How do I get the furl value into the ajax ?
- var curprotocol = window.location.protocol + '//';
- var curhostnm = window.location.hostname;
- var curpath = window.location.pathname;
- var curlseturl = curprotocol + curhostnm + curpath + 'includes/setsacookie.php';
- console.log('CurSetUrl: ' + curlseturl);
- $.get(curlseturl)
- .done(function() {
- // exists code
- var furli = 'includes/setsacookie.php';
- console.log('FinalUrl-Done: ' + furli);
- var furl = furli;
- }).fail(function() {
- // not exists code
- var furli = curprotocol + curhostnm + 'includes/setsacookie.php';
- console.log('FinalUrl-Fail: ' + furli);
- var furl = furli;
- });
- console.log('Furl-Final: ' , furl);
- $.ajax({
- method: 'POST',
- dataType: 'json',
- processData: false,
- contentType: false,
- url: furl,
- data: trackData
- })
- .done (function(data) {
- if (data.exists == true) {$('.myclass').hide()}
- })
- .fail(function(data) {
- });