Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在页面中加载另一个页面并附加另一个url_Javascript_Php_Jquery_Ajax - Fatal编程技术网

Javascript 在页面中加载另一个页面并附加另一个url

Javascript 在页面中加载另一个页面并附加另一个url,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我到处都找过这个,但不知道怎么做 我想有一个页面顶部的链接,如;新闻|评论|图片等 当有人点击其中一个链接时,我希望它从另一个php文件加载内容,同时将链接名附加到url上。示例:Example.com/page1/review 我见过其他网站这样做 我没有任何代码示例,因为我甚至不确定如何开始。我尝试了.Load,但没有发现它有效。您可以使用,您可以使用pushState或replaceState来替换url history.pushState({},"","/the/new/url"); /

我到处都找过这个,但不知道怎么做

我想有一个页面顶部的链接,如;新闻|评论|图片等

当有人点击其中一个链接时,我希望它从另一个php文件加载内容,同时将链接名附加到url上。示例:Example.com/page1/review

我见过其他网站这样做

我没有任何代码示例,因为我甚至不确定如何开始。我尝试了.Load,但没有发现它有效。

您可以使用,您可以使用pushState或replaceState来替换url

history.pushState({},"","/the/new/url");
//or
history.replaceState({},"","/the/new/url");
两个函数的参数相同。第一个是存储并传递给onpopstate事件的对象。您还可以在浏览器重新启动时通过
history.state
检索它

第二个是标题字符串,我相信目前没有浏览器充分利用它,所以它可以是任何东西

最后一个参数是要在地址栏中显示的新url

因此,如果您想加载图像链接,并且希望url看起来像
/Images
,您可以执行以下操作

jQuery("#content").load("/images.php").then(function(){
   history.replaceState({},"","/Images");
});

既然您用jQuery标记了问题,我假设您正在使用库。查看jQuery中的
ajax
函数的文档。在没有看到您的代码的情况下,我无法提供具体的代码来帮助您,但下面是一个示例:

$.ajax({
    url: "example.com/page1/" + variable + "/index.php", 
    success: function(result){
        $("#div").html(result);
    }
});

谢谢你的帮助,我会试试的。