0

I think it must be easy, but still, can not figure out how to solve this. So I've got a variable that contains a URL:

> var siteurl = 'http://my-site.com';

All I need is to add "siteurl" variable into another url before /load.php

function load(){
    $.getJSON('/load.php', function(data) {
        appendComments(data);
    });
}

So that the ultimate url was

http://my-site.com/load.php

  • 1
    siteurl + '/load.php' – gaetanoM Sep 10 '17 at 19:41
  • Possible duplicate of [What's the best way to do string building/concatenation in JavaScript?](https://stackoverflow.com/questions/31845895/whats-the-best-way-to-do-string-building-concatenation-in-javascript) – Josh K Sep 10 '17 at 19:45

1 Answers1

3

You can merge a string variable with another string using +

function load(){
    var siteurl = 'http://my-site.com';
    var url = siteurl + '/load.php';
    $.getJSON(url, function(data) {
        appendComments(data);
    });
}
Jesper Johansson
  • 599
  • 3
  • 14