Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.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
Jquery 使用表单元素将页面加载到div中并更新地址栏_Jquery_Html_Css - Fatal编程技术网

Jquery 使用表单元素将页面加载到div中并更新地址栏

Jquery 使用表单元素将页面加载到div中并更新地址栏,jquery,html,css,Jquery,Html,Css,我正在尝试开发一个网站,做一件我在普通网页中看到的非常标准的事情。我有一个index.html页面,其中有一个菜单栏,用户可以通过它导航到其他页面。现在,我不再打开单独的页面,而是在同一index.html页面的中加载其他页面的内容 允许我这样做的脚本如下所示: <script src="http://code.jquery.com/jquery-latest.js"></script> <script> function getPage(url) {

我正在尝试开发一个网站,做一件我在普通网页中看到的非常标准的事情。我有一个
index.html
页面,其中有一个菜单栏,用户可以通过它导航到其他页面。现在,我不再打开单独的页面,而是在同一
index.html
页面的
中加载其他页面的内容

允许我这样做的脚本如下所示:

<script src="http://code.jquery.com/jquery-latest.js"></script>
 <script>
 function getPage(url) {
    $("#content-wrapper").load(url);
 }
 </script>'

函数getPage(url){
$(“#内容包装器”).load(url);
}
'
导航链接如下所示:

<a href="#" title="" class="active" onclick="getPage(&#39;./web/contact/contact.html&#39;);">Contact</a>

这工作正常,除了内容加载到
index.html
站点之外,浏览器地址栏中的
URL
没有改变。因此,如果我刷新页面,我将被带到主页。因此,用户将无法使用
URL
共享任何特定页面

我试图找到人们做这件事的方法,发现他们大多使用
form
元素和
post
方法,但找不到一个好的教程来做这件事。我发现的另一个答案是使用,但不确定哪一个更好


对此,我们非常感谢任何解决方案或指导。

考虑使用一些基本的PHP,并学习以这种方式制作模板

非常基本的例子:

index.php:

<?PHP
if (isset($_GET['page'])
{
    $pageURL = 'pages/'.$myPage.'.php';
    if (!file_exists ($pageURL))
        die("invalid page");
} else {
    $pageURL = 'pages/home.php';
}
$myPage = $_GET['page'];
?>
<html>
<body>
<div id="header">
    <?PHP include('header.php');?>
</div>
<div id="body">
    <?PHP include($pageURL);?>
</div>
<div id="footer">
    <?PHP include('footer.php');?>
</div>
</body>
</html>

考虑使用一些基本的PHP,并学习以这种方式制作模板

非常基本的例子:

index.php:

<?PHP
if (isset($_GET['page'])
{
    $pageURL = 'pages/'.$myPage.'.php';
    if (!file_exists ($pageURL))
        die("invalid page");
} else {
    $pageURL = 'pages/home.php';
}
$myPage = $_GET['page'];
?>
<html>
<body>
<div id="header">
    <?PHP include('header.php');?>
</div>
<div id="body">
    <?PHP include($pageURL);?>
</div>
<div id="footer">
    <?PHP include('footer.php');?>
</div>
</body>
</html>

考虑使用一些基本的PHP,并学习以这种方式制作模板

非常基本的例子:

index.php:

<?PHP
if (isset($_GET['page'])
{
    $pageURL = 'pages/'.$myPage.'.php';
    if (!file_exists ($pageURL))
        die("invalid page");
} else {
    $pageURL = 'pages/home.php';
}
$myPage = $_GET['page'];
?>
<html>
<body>
<div id="header">
    <?PHP include('header.php');?>
</div>
<div id="body">
    <?PHP include($pageURL);?>
</div>
<div id="footer">
    <?PHP include('footer.php');?>
</div>
</body>
</html>

考虑使用一些基本的PHP,并学习以这种方式制作模板

非常基本的例子:

index.php:

<?PHP
if (isset($_GET['page'])
{
    $pageURL = 'pages/'.$myPage.'.php';
    if (!file_exists ($pageURL))
        die("invalid page");
} else {
    $pageURL = 'pages/home.php';
}
$myPage = $_GET['page'];
?>
<html>
<body>
<div id="header">
    <?PHP include('header.php');?>
</div>
<div id="body">
    <?PHP include($pageURL);?>
</div>
<div id="footer">
    <?PHP include('footer.php');?>
</div>
</body>
</html>

您可以通过向getPage函数添加以下内容来更改地址栏中的url

if('pushState' in history)
     history.pushState(null,'',url);

但是,如果现在点击reload,您将只获得div的内容,而不是index.html。因此,您需要实现服务器代码来返回index.html,其中包含每个url的正确内容

您可以通过向getPage函数添加以下内容来更改地址栏中的url

if('pushState' in history)
     history.pushState(null,'',url);

但是,如果现在点击reload,您将只获得div的内容,而不是index.html。因此,您需要实现服务器代码来返回index.html,其中包含每个url的正确内容

您可以通过向getPage函数添加以下内容来更改地址栏中的url

if('pushState' in history)
     history.pushState(null,'',url);

但是,如果现在点击reload,您将只获得div的内容,而不是index.html。因此,您需要实现服务器代码来返回index.html,其中包含每个url的正确内容

您可以通过向getPage函数添加以下内容来更改地址栏中的url

if('pushState' in history)
     history.pushState(null,'',url);

但是,如果现在点击reload,您将只获得div的内容,而不是index.html。因此,您需要实现服务器代码来返回index.html,其中包含每个url的正确内容

没有多少人会在div中加载页面进行导航,但实际上你想做的是欺骗地址栏,出于明显的安全原因,这是不可能的。您应该使用模板驱动的PHP设计在页面之间共享导航栏、侧栏、页脚等元素,因为在刷新问题的同时,您还将遇到用户试图导航回、书签、共享页面等问题。请尝试使用
$.holdReady()
历史记录
,将加载内容的
location
设置为
index.html#id
,如果
index.html#id
已重新加载,请在
事件之前调用
.load(#id”)
;请看@wobbles,这不是不可能的,请看这是一种非常丑陋的页面导航方式,在这一点上,最好使用iframe,省去麻烦。没有多少人在div中加载页面进行导航,但你想做的基本上是伪造地址栏,出于明显的安全原因,这是不可能的。您应该使用模板驱动的PHP设计在页面之间共享导航栏、侧栏、页脚等元素,因为在刷新问题的同时,您还将遇到用户试图导航回、书签、共享页面等问题。请尝试使用
$.holdReady()
历史记录
,将加载内容的
location
设置为
index.html#id
,如果
index.html#id
已重新加载,请在
事件之前调用
.load(#id”)
;请看@wobbles,这不是不可能的,请看这是一种非常丑陋的页面导航方式,在这一点上,最好使用iframe,省去麻烦。没有多少人在div中加载页面进行导航,但你想做的基本上是伪造地址栏,出于明显的安全原因,这是不可能的。您应该使用模板驱动的PHP设计在页面之间共享导航栏、侧栏、页脚等元素,因为在刷新问题的同时,您还将遇到用户试图导航回、书签、共享页面等问题。请尝试使用
$.holdReady()
历史记录
,将加载内容的
location
设置为
index.html#id
,如果
index.html#id
已重新加载,请在
事件之前调用
.load(#id”)
;请看@wobbles,这不是不可能的,请看这是一种非常丑陋的页面导航方式,在这一点上,最好使用iframe,省去麻烦。没有多少人在div中加载页面进行导航,但你想做的基本上是伪造地址栏,出于明显的安全原因,这是不可能的。您应该使用模板驱动的PHP设计来在页面之间共享导航栏、侧栏、页脚等元素,因为在刷新问题的同时,您还将遇到用户试图刷新的问题