dplanet
dplanet

Reputation: 5403

Auto-refreshing using ajax

I have the following function which updates a time_remaining span on the page.

function update() {
  $.ajax({
    type: 'POST',
    url: 'check_time.php',
    data: 'checktime=true',
    timeout: 2000,
    success: function(data) {
        $(".time_remaining").html(data);
        window.setTimeout(update, 2000);
        var time=(html(data));
        alert(time);
        if(time<=0)
        {
            $(".time_remaining").html("now");
        }
        else
        {
            $(".time_remaining").html(data);
        }
    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {
      $("#notice_div").html('Timeout contacting server..');
      window.setTimeout(update, 60000);
    }
});
};

My only problem is this line:

var time=(html(data));

It simply does not define the variable correctly. Any pointers?

Upvotes: 0

Views: 293

Answers (2)

FiveTools
FiveTools

Reputation: 6030

(html(data)) is not a defined method used in this fasion.

var time = $(".time_remaining").html();

or

var time = data;

Upvotes: 1

Sorin S.
Sorin S.

Reputation: 229

How about if you use only

var time = data;

Upvotes: 1

Related Questions