简体   繁体   English

如何将可变内容添加到URL

[英]How do I add a variable content into URL

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: 所以我有一个包含URL的变量:

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

All I need is to add "siteurl" variable into another url before /load.php 我需要做的就是在/load.php之前的另一个URL中添加“ siteurl”变量

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

So that the ultimate url was 这样最终的网址是

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

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);
    });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM