我正在使用jQuery动态加载div容器中的内容.
服务器端代码检测请求是AJAX还是GET.
我希望浏览器后退/前进按钮使用代码,所以我尝试使用history.pushState.我必须遵循一段代码:
$('.ajax').on('click', function(e) {
e.preventDefault();
$this = $(this);
$('#ajaxContent').fadeOut(function() {
$('.pageLoad').show();
$('#ajaxContent').html('');
$('#ajaxContent').load($this.attr('href'), function() {
window.history.pushState(null,"", $this.attr('href'));
$('.pageLoad').hide();
$('#ajaxContent').fadeIn();
});
});
});
Run Code Online (Sandbox Code Playgroud)
一切正常,除非使用浏览器后退/前进按钮浏览时,栏中的地址会根据计划更改,但页面不会更改.我究竟做错了什么?
在Clayton的回答帮助下更新了脚本
var fnLoadPage = function(url) {
$('#ajaxContent').fadeOut(function() {
$('.pageLoad').show();
$('#ajaxContent').html('').load(url, function() {
$('.pageLoad').hide();
$('#ajaxContent').fadeIn();
});
});
};
window.onpopstate = function(e) {
fnLoadPage.call(undefined, document.location.href);
};
$(document).on('click', '.ajax', function(e) {
$this = $(this);
e.preventDefault();
window.history.pushState({state: new Date().getTime()}, '', $this.attr('href'));
fnLoadPage.call(undefined, $this.attr('href'));
});
Run Code Online (Sandbox Code Playgroud) 我想使用PHP访问skyDrive.我想要检索文件和文件夹列表,下载,上传和删除文件.
我有一个microsoft开发者clientID和clientSecret.
任何人都可以让我开始使用OAuth连接到skyDrive并使用API吗?
非常感谢!
我正在尝试使用Enzyme describeWithDOM()和mount().来测试React Components行为.但是当组件导入jQuery时,我收到此错误:
错误:jQuery需要一个带文档的窗口
我知道Enzyme在引擎盖下使用了jsdom,我一直认为jsdom负责窗户和文件.但我似乎无法找到如何让这些工作在一起.
测试代码如下所示:
import chai, {expect} from 'chai';
import Select from './Select';
import React, {createElement} from 'react';
import {describeWithDOM, mount} from 'enzyme';
describe('UI Select', () => {
//more shallow tests here
describeWithDOM('User Actions', () => {
it('Toggles the .ui-options menu on button click', () => {
const wrapper = mount(<Select {...baseProps} />);
expect(wrapper.state().open).to.not.be.ok;
wrapper.find('button').simulate('click');
expect(wrapper.state().open).to.be.ok;
});
});
}
Run Code Online (Sandbox Code Playgroud)
在按钮onClick方法中,调用了一个jquery函数: $('#inputSelector').focus()
我怎样才能让Enzyme和jsdom在测试中使用jquery?
如何删除数据库中created_at或updated_at字段早于60分钟的所有Eloquent记录?(或示例中的任意时间)
编辑:按照 @Alexxus 建议发布解决方案作为答案