0

I develop tool to get JSON data with JQuery but the problem is some variables don't put their values and I've got the variable name like a text only. This the code

$(document).ready(function(){
$('.HTML').each(function(){
var call = $.getJSON('http://test-khamsat-support-gig.blogspot.com/feeds/posts/default/-/Break?max-results=10&orderby=published&alt=json-in-script&callback=?',function(data){
var cont = data.version;
    });

    var th = $(this);
     var b = th.html(),
            a = b.match(/[^[\]]+(?=])/g);
          if(a){
            if(a[2] == 'one'){
                th.append("<h1>'+cont+'</h1>")
            }
          }
    }); 
  });

The code will run just in my blog because it content my blog feed

abdel
  • 103
  • 1
  • 2
  • 12

1 Answers1

4

Try

$(document).ready(function () {
    $('.HTML').each(function () {
        //store the reference to the element to use inside the callback
        var th = $(this);
        $.getJSON('http://test-khamsat-support-gig.blogspot.com/feeds/posts/default/-/Break?max-results=10&orderby=published&alt=json-in-script&callback=?', function (data) {
            var cont = data.version;

            //move this inside the ajax callback to support async nature
            var b = th.html(),
                a = b.match(/[^[\]]+(?=])/g);
            if (a) {
                if (a[2] == 'one') {
                    //use proper string concatenation here
                    th.append('<h1>' + cont + '</h1>')
                }
            }
        });
    });
});
Community
  • 1
  • 1
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
  • Thank you so much it works great. I will choose your answer as the correct one when I will be able to do that (after 6 min). – abdel Mar 04 '14 at 13:25