0

I have below code for parse some json and make other things :

<!doctype html> <html> <head> <title>Parsing</title> <script type="text/javascript" src="jquery-2.1.0.min.js"></script> <link rel="stylesheet" href="css/index.css" type="text/css" /> </head> <script> $.getJSON( 'http://sath3g.altervista.org/index.php', { get_param: 'value' }, function(data) { // 'data' is an array of objects here for(var i=0; i<data.length; i++) { //data[i] is an individual line of excel data var lin = data[i]["Nr SAT"]; $('body').append($('<p>').html('Numero Sat: '+ '<a href = http://sath3g.altervsta.org/jsonint.html+?id='+lin '>'+ data[i]["Nr SAT"]+ '</a>')); $('body').append($('<p>').html('Data: '+ data[i]["Data"])); //http://sath3g.altervsta.org/jsonint.html +?id=+lin } }); </script> <body> <header> </header> </body> </html> 

In the line of code below, I want to put in the link using variable lin. But it doesn't work.

$('body').append($('<p>').html('Numero Sat: '+ '<a href =http://sath3g.altervsta.org/jsonint.html+?id='+lin '>'+ data[i]["Nr SAT"]+ '</a>')); 

What is wrong here?

2 Answers 2

1

You're missing a + concatenation character after the lin variable. Try this:

$('body').append($('<p>').html('Numero Sat: <a href ="http://sath3g.altervsta.org/jsonint.html+?id=' + lin + '">'+ data[i]["Nr SAT"] + '</a>')); 

Better yet, build the DOM elements instead of concatenating ugly strings.

var $p = $('<p />'); var $a = $('<a />', { href: 'http://sath3g.altervsta.org/jsonint.html+?id=' + lin, text: data[i]["Nr SAT"] }); $('body').append($p.append($a)); 
Sign up to request clarification or add additional context in comments.

Comments

0

You are missing '+' after lin

$('body').append($('<p>').html('Numero Sat: '+ '<a href =http://sath3g.altervsta.org/jsonint.html+?id='+lin+'>'+ data[i]["Nr SAT"]+ '</a>')); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.