Reputation: 391
I have some json data that I need to append to the end of a url
var myData = "https://example.com/json"
$.getJSON(myData, function(data) {
var url = data[0]['link'];
$('#some-div').html('<div data-href="https://example.com/+urlhere+">');
});
Not sure how I can do this. Any idea?
Upvotes: 0
Views: 373
Reputation: 781096
Use string concatenation. Also, encode it with encodeURIComponent
var myData = "https://example.com/json"
$.getJSON(myData, function(data) {
var url = data[0]['link'];
$('#some-div').html('<div data-href="https://example.com/"' + encodeURIComponent(url) + '">');
});
Upvotes: 1