Northify
Northify

Reputation: 391

Append json data to end of url

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

Answers (1)

Barmar
Barmar

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

Related Questions