- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 ajax 从另一个页面加载 div,但使用 History API 保持 URL 完整性。 ajax 和历史记录部分正在工作(即 div 正在加载并且 url 正在更改),但由于某种原因,我的 div 包含我的整个页面,而不仅仅是 div 中应有的内容!
原始页面和正在加载的页面 div 都是这种情况。
剥离 HTML
<!DOCTYPE html>
<html>
<body>
<div id="slider">
... all the page content
<a rel='tab' href="p/password.jsf">Forgot password?</a>
</div>
</body>
</html>
JS
<script>
$(function(){
$("a[rel='tab']").click(function(e){
//get the link location that was clicked
pageurl = $(this).attr('href');
//to get the ajax content and display in div with id 'content'
$.ajax({
url:pageurl + '?rel=tab',
success: function(data){
$('#slider').html(data);
}});
//to change the browser URL to 'pageurl'
if(pageurl!=window.location){
window.history.pushState({path:pageurl},'',pageurl);
}
return false;
});
});
/* the below code is to override back button to get the ajax content without reload*/
$(window).bind('popstate', function() {
$.ajax({
url:location.pathname+'?rel=tab',
success: function(data){
$('#slider').html(data);
}});
});
</script>
最佳答案
如果您想使用ajax获取页面的一部分,那么您可以使用带有元素的id
的load
方法来从中获取内容。
$('#slider').load(pageurl + '?rel=tab #container_with_content_to_fetch', function() {
alert('callback after success.');
});
有关load()
的更多信息:info
关于javascript - 为什么我的 div 充满了整个页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15343794/
我有一个 Storm 拓扑,其中一个 bolt 应该与ElasticSearch交互。 public static Client client; public static Settings sett
我目前正在开发 LIMS。我需要检索与需要使用某种准备方法准备的实验室 sample 相关的信息。 (我对此进行了相当多的简化,因此对任何错误表示歉意。)我需要在查询结果中生成的列是: Sample
我必须以下文件夹结构: main - server -- server-module-1 --- a --- b --- c -- server-module-2 --- d --- e --- f
Tomcat 和我的自定义 JAAS LoginModule 运行良好,但每次我输入错误的凭据时,整个 LoginException 都会写入日志。根据定义,LoginModule 必须在身份验证失败
我一直在关注有关 iOS 开发的教程 - 特别是向下钻取 UITableViews。我建立了自己的自定义 plist,但我似乎无法让 DetailViewController 填充我的 plist 信
我对 QT 比较陌生。在我的代码中,我创建了一个 QTableWidget,遍历行并将单元格设置为 QLineEdits 和 QCheckBoxes。我想这样做,以便更改任何 QLineEdits 中
我刚开始使用 Chrome 的分析器。所以这可能是对我得到的结果的误解。 如果我打开 Chrome 分析器并拍摄以下网页的堆快照,我会注意到 obj3 的保留大小是 obj1 和 obj2 的保留大小
我正在尝试使用 Python 2.7 中的 BeautifulSoup 4 解析 youtube 评论。当我尝试播放任何 YouTube 视频时,我会收到充满 BOM 的文本,而不仅仅是在文件开头:
我有此消息的完整系统日志: mysqld[963]: 2016-10-23 20:54:14 140708269390592 [警告] 拒绝用户 ''@'localhost' 访问(使用密码:NO)
我有一个数组,里面装满了NSDictionaries。我想找到其中一本字典的 index,但我对这本字典的了解只是键 @"name"的 value。我该怎么做 ? 最佳答案 在 theArray 中查
我想在之前的div内容满了文字的时候显示div,然后继续用剩下的文字填充这个新的div。 我不知道怎么办。事实上,在下面的代码中我写道,div 是在单击按钮时显示的。我也无法设置上面解释的“填充操作”
这是发生了什么: 内部数据库内容:一个类有一个字符串属性,用于存储电话号码。这个数字是使用代码设置的 CFBridgingRelease(ABMultiValueCopyValueAtIndex(AB
我的 logcat 中收到了数千条以下警告消息,它挤掉了我实际要查找的消息: W/ActivityManager﹕ Wtf, activity ActivityRecord{4338cd90 u0 u
我尝试使用 mongoimport 在 mongodb 中导入单个 csv 文件,使用 mongoimport -d mydb -c things --type csv --file location
我的 Rails 开发日志中有大量这样的行: Started GET "/assets/services.css?body=1" for 127.0.0.1 at 2012-11-26 02:27:4
我在 Xcode 8/iOS 10/Swift 3 中遇到 Firebase 问题。试图让 Firebase Analytics 全部设置好。但是在 iOS10 中,控制台会记录来自 Firebase
我的 logcat 中充满了以下消息 - E/UsDebuggingManager( 476): java.io.IOException: Connection refused E/UsDebugg
总结 我有各种单节点 Kubernetes 集群,这些集群在累积约 300 个已完成的作业后变得不稳定。 例如,在一个集群中,有 303 个已完成的作业: root@xxxx:/home/xxxx#
我是一名优秀的程序员,十分优秀!