ChrisianBartram
ChrisianBartram

Reputation: 753

Ajax string comparison

I have a basic ajax function

 setInterval(function() {
      var action = '';
      var status = '';
      $('#php-data').load('../Data/Dashboard.Data.php'); 
      $.ajax({type: 'POST', url: 'Data/Dashboard.Image.php', data: { json: action }, dataType: 'json' }).done(function(data) {
          console.log('Ajax Data: ' + data);
          status = JSON.parse(data);
          **if(status === 'false') {**
              console.log("script is NOT running");
              drawPieChart();
          } else {
              console.log("script is running");
            $('#php-image').load('../Data/Dashboard.Image.php'); //todo only load this is the ajax returned from Dashboard.image.php is true
          }
      });            
  }, 5000);

basically the only thing my ajax returns is "false" so when I compare status to false it should be true and drawPieChart(); but instead it always runs the jquery load() function even though my ajax data is returning false every single time. ive also tried this:

 setInterval(function() {
      var action = '';
      var status = '';
      $('#php-data').load('../Data/Dashboard.Data.php'); 
      $.ajax({type: 'POST', url: 'Data/Dashboard.Image.php', data: { json: action }, dataType: 'json' }).done(function(data) {
          console.log('Ajax Data: ' + data);
          status = data;
          **if(status === 'false') {**
              console.log("script is NOT running");
              drawPieChart();
          } else {
              console.log("script is running");
            $('#php-image').load('../Data/Dashboard.Image.php'); //todo only load this is the ajax returned from Dashboard.image.php is true
          }
      });            
  }, 5000);

and this :

 setInterval(function() {
      var action = '';
      $('#php-data').load('../Data/Dashboard.Data.php'); 
      $.ajax({type: 'POST', url: 'Data/Dashboard.Image.php', data: { json: action }, dataType: 'json' }).done(function(data) {
          console.log('Ajax Data: ' + data);
          **if(data == 'false') {**

              console.log("script is NOT running");
              drawPieChart();
          } else {
              console.log("script is running");
            $('#php-image').load('../Data/Dashboard.Image.php'); //todo only load this is the ajax returned from Dashboard.image.php is true
          }
      });            
  }, 5000);

Upvotes: 2

Views: 2464

Answers (1)

user6105365
user6105365

Reputation:

if(status === 'false')

This suggests a string. use this instead:

if(status == false)

you could simplify it even further like so:

if(!status)

Upvotes: 1

Related Questions