setInterval in javascript does not add

1

Well, I have the following javascript code and when I try to sum the strMessage it does not add, but it adds side by side to the value and so on every time it executes, what am I doing wrong? p>

function main() {

  var s = 0;
  //Espera um segundo
  setInterval(function() {

$.ajax({
  url: 'teste3.php',
  success: function(strMessage) {

    s += strMessage;
  },
});

document.write(s);

  }, 1000);
}

window.onload = main;
    
asked by anonymous 17.09.2017 / 02:41

1 answer

2

Maybe I would have to do strMessage a number in javascript

s += parseInt(strMessage); 

or with decimals:

parseFloat ()

    
17.09.2017 / 03:16