我想通过AJAX(jQuery load方法)加载页面并通过该history.pushState方法将URL推送到浏览器栏时保留后退按钮功能.单击浏览器后退按钮时出现问题,第一次单击仅恢复以前的URL但不加载上一页.
到目前为止,这是我的代码:
$(function(){
var profile_url= "/profile";
$('#click_button').click(function(){
$('#main_content').load(profile_url);
history.pushState({profile:profile_info}, "profile", profile_url);
});
});
Run Code Online (Sandbox Code Playgroud)
我的问题是,有没有办法#main_content在第一次单击后退按钮时将前一页的AJAX加载到div中?
任何帮助/建议将不胜感激.
我不明白在JavaScript中何时使用"原型"一词与使用简单的"点"符号而不使用"原型"一词.有人可以查看这些代码块并帮助我了解您何时想要使用其中一个代码块?
与 "原型":
function employee(name,jobtitle)
{
this.name=name;
this.jobtitle=jobtitle;
}
var fred=new employee("Fred Flintstone","Caveman");
employee.prototype.salary=null;
fred.salary=20000;
console.log(fred.salary);
Run Code Online (Sandbox Code Playgroud)
没有 "原型":
function employee(name,jobtitle,salary)
{
this.name=name;
this.jobtitle=jobtitle;
this.salary=salary;
}
var fred=new employee("Fred Flintstone","Caveman", 20000);
console.log(fred.salary);
Run Code Online (Sandbox Code Playgroud) 在我的网站上,我想做一些像Stackoverflow这样的评论推送通知.亚马逊SNS/SQS似乎提供了一个框架来实现这一点,但我很难在网上找到任何超出"hello world"等级的代码/解释.
从阅读AWS SNS/SQS文档看起来我需要以下内容:
逻辑:
发布评论的页面上的PHP(http://mysite.com/postCommentOrAnswer.php):
$comment=$_POST['comment']; //posted comment
require_once 'application/third_party/AWSSDKforPHP/sdk.class.php';
$sns = new AmazonSNS();
$response = $sns->create_topic('SO-like-question-12374940'); //create topic
$response = $sns->publish(
'arn:aws:sns:us-east-1:9876543210:SO-like-question-12374940',
$comment
); //publish comment
$response = $sns->subscribe(
'arn:aws:sns:us-east-1:9876543210:SO-like-question-12374940',
'https ',
'https://mysite.com/notificationsReceiver'
); // Subscribe to notifications
Run Code Online (Sandbox Code Playgroud)
收到通知的页面上的PHP(http://mysite.com/notificationsReceiver.php):
no idea, thoughts?
Run Code Online (Sandbox Code Playgroud)
显然,这并不是一个完整的演示,可能有一些不正确的函数调用,但我想知道是否有人可以帮助建立这个?
php amazon-sqs push-notification amazon-web-services amazon-sns
标题或多或少都说明了一切.从Cloudfront管理控制台的"限制查看器访问"部分(下图)使用单选按钮这一事实来看,它似乎是一种情况.
问题:是否有其他方法可以解析一个S3的存储桶,使其既可以公开(也可以是任何人查看),也可以包含私有(即签名网址)内容?
我正在尝试跟进之前的Stackoverflow问题,该问题涉及如何在外部HTML元素(如a)中显示Cleditor文本框中的内容<p>.这是在webkit浏览器中解决我的问题而不是Firefox或IE 的问题和小提琴:
这是小提琴的代码:
<textarea id="input" name="input"></textarea>
<p id="x"></p>
<script>
$("#input").cleditor();
$(".cleditorMain iframe").contents().find('body').bind('keyup',function(){
var v = $(this).text(); // or .html() if desired
$('#x').html(v);
});
</script>
Run Code Online (Sandbox Code Playgroud)
我已经阅读了从jquery获取iframe的内容,我需要使用"window.top ....访问主页并以这种方式传递它,因为所有浏览器都不支持.contents()"但我不是确定如何使用window.top为此目的,并希望有人可能能够阐明这个主题.
/(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,8}/
此RegEx应该验证密码,该密码应至少包含一个数字,包括小写和大写字符.任何人都可以用更小的组件解释这个RegEx吗?
在下面的对象中,我想将属性名称更改thumb为thumbnail.我还想更改titleto include <span>标记的值.
这是我的目标:
var data = [{
thumb: '/images/01.png',
title: 'My title',
},{
thumb: '/images/02.png',
title: 'My title',
},{
thumb: '/images/03.png',
title: 'My title',
}];
Run Code Online (Sandbox Code Playgroud)
这是我想要的样子:
var data = [{
thumbnail: '/images/01.png',
title: '<span class="red">title 1</span>',
},{
thumbnail: '/images/02.png',
title: '<span class="red">title 2</span>',
},{
thumbnail: '/images/03.png',
title: '<span class="red">title 3</span>',
}];
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的不起作用:
var i=0, count=data.length;
for (i=0;i<=count;i++){
data[i].thumbnail=data[i].thumb;
data[i].title="<span class='red'>"+data[i].title+"<span>";
}
Run Code Online (Sandbox Code Playgroud) 如果我为一个zip文件创建href一个链接的URL 并单击该链接,我的zip文件将被下载并打开它获取我期望的内容.
这是HTML:
<a href="http://mysite.com/uploads/my-archive.zip">download zip</a>
Run Code Online (Sandbox Code Playgroud)
问题是我想指向我的应用程序的链接,以便我可以确定用户是否有权访问此zip文件.
所以我希望我的HTML是这样的:
<a href="/canDownload">download zip</a>
Run Code Online (Sandbox Code Playgroud)
和我的PHP /canDownload页面:
//business logic to determine if user can download
if($yesCanDownload){
$archive='https://mysite.com/uploads/my-archive.zip';
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=".basename($archive));
header("Content-Length: ".filesize($archive));
ob_clean();
flush();
echo readfile("$archive");
}
Run Code Online (Sandbox Code Playgroud)
所以,我认为这个问题与header()代码有关,但我已经尝试了一些基于各种谷歌和其他SO建议相关的东西,但没有工作.
如果你回答我的问题,很可能你也可以回答这个问题:带有PHP的压缩文件在提取后产生cpgz文件
所以据说从Firefox> 4开始,绑定窗口jQuery对象beforeunload不再起作用了.
我想做的是提交AJAX帖子来删除我的服务器的memcache数据.
当我刷新唯一的打开选项卡时,我可以看到beforeunload使用以下代码在firefox和chrome中调用该事件,如console.log消息"firefox/NON-firefox delete"所示.问题是我从未看到console.log消息"memcache delete",表明我的服务器从未看到过$.ajax请求.
我意识到浏览器嗅探是不好的,并且if和else语句中包含的内容之间没有区别.我只是展示了我在Firefox中尝试失败的代码.
有人有主意吗?
$(window).bind('beforeunload', function(){
if(/Firefox[\/\s](\d+)/.test(navigator.userAgent) && new Number(RegExp.$1) >= 4) {
console.log('firefox delete');
memcacheDelete();
return null;
}
else {
console.log('NON-firefox delete');
memcacheDelete();
return null;
}
});
function memcacheDelete() {
$.ajax({
url: "/memcache/delete",
type: "post",
data:{},
success:function(){
console.log('memcache deleted');
}//success
}); //ajax
}
Run Code Online (Sandbox Code Playgroud) javascript ×6
jquery ×3
php ×2
ajax ×1
amazon-rds ×1
amazon-s3 ×1
amazon-sns ×1
amazon-sqs ×1
cleditor ×1
dom ×1
for-loop ×1
http-headers ×1
iframe ×1
innodb ×1
myisam ×1
mysql ×1
object ×1
prototype ×1
pushstate ×1
regex ×1
zip ×1
zipfile ×1