T
T
Tynay Bakasov2019-12-18 03:50:57
JavaScript
Tynay Bakasov, 2019-12-18 03:50:57

js code not working?

Good day.
there is a json file

{
"artist":"ALAN WALKER",
"title":"Ghost"
}

var myVar = setInterval(function(){ nowtrack() }, 1000);
function nowtrack() {
$(document).ready(function(){			
    $.getJSON('https://site.ru/json.txt', {}, function(json){  

      $('#nowtrack').html('');
    $('#nowtrack').append('<div class="artist">'   + json.artist + '</div >')
    $('#nowtrack').append('<div class="title">'   + json.title + '</div >')
    }); 
});
}

I've tried many options and it doesn't work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tynay Bakasov, 2019-12-19
@Yobanaris

this code works

var myVar = setInterval(function() {
  nowtrack()
}, 1000);

function nowtrack() {
  $(document).ready(function() {
    $.getJSON('https://www.site.ru/xml/json.txt', {}, function(json) {

      $('#nowtrack').html('');
      $('#nowtrack').append('<div class="artist">' + json.artist + '</div >')
      $('#nowtrack').append('<div class="title">' + json.title + '</div >')
      $('#nowtrack').append('<img src="' + json.image600 + '" style="width: 250px;";>')
    });
  });
}
jQuery.3.3.1
<div id="nowtrack">

</div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question