Pass variable from get into ajax

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 ?

  1. var curprotocol = window.location.protocol + '//';
  2. var curhostnm = window.location.hostname;
  3. var curpath = window.location.pathname;
  4. var curlseturl = curprotocol + curhostnm + curpath + 'includes/setsacookie.php';
  5.   console.log('CurSetUrl: ' + curlseturl);
  6. $.get(curlseturl)
  7.     .done(function() { 
  8.       // exists code
  9.       var furli = 'includes/setsacookie.php';
  10.       console.log('FinalUrl-Done: ' + furli);
  11.       var furl = furli;
  12.     }).fail(function() { 
  13.       // not exists code
  14.       var furli = curprotocol + curhostnm + 'includes/setsacookie.php';
  15.       console.log('FinalUrl-Fail: ' + furli);
  16.       var furl = furli;
  17.     });
  18.  console.log('Furl-Final: ' , furl);
  19.     $.ajax({
  20.       method: 'POST',
  21.       dataType: 'json',
  22.       processData: false,
  23.       contentType: false,
  24.       url: furl,
  25.       data: trackData
  26.     })
  27.     .done (function(data) {
  28.       if (data.exists == true) {$('.myclass').hide()}
  29.     })
  30.     .fail(function(data) {
  31.     });