https://github.com/jazz-man/ajaxloader
Asynchronous page loading using Javascript History API
https://github.com/jazz-man/ajaxloader
Last synced: 3 months ago
JSON representation
Asynchronous page loading using Javascript History API
- Host: GitHub
- URL: https://github.com/jazz-man/ajaxloader
- Owner: Jazz-Man
- Created: 2017-02-26T18:25:49.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-06-10T10:33:49.000Z (almost 9 years ago)
- Last Synced: 2025-01-02T11:26:59.563Z (5 months ago)
- Language: JavaScript
- Size: 35.2 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ajaxpageloader
Asynchronous page loading using Javascript History API and Promises
## Install
`bower i ajaxloader --save (coming soon)`## Init
### Page loading
Fetches new content and replaces current one.
``` js
document.ajaxLoader({
wrapper: 'body', //the scope where to activate the script
anchors: 'a:not([target="_blank"]):not([href="#"])',
container: 'main', //where to load the new content
siteName: 'Your Site Name',
waitBeforeLoading: 250,
beforeLoading: function(container) {
//Scripts executed before the ajax request
},
afterLoading: function(container) {
//Scripts executed after the ajax request
}
});
```
### Content loading
Fetches new content and appends to current one
``` js
document.ajaxLoader({
cors: true,
container: 'main', //where to load the new content
ajaxUrl: 'http://your-ajax-url.com',
ajaxData: { //All the data to send to the server
action: 'your_action',
offset: 10,
category: 'category'
},
beforeLoading: function(container) {
//Scripts executed before the ajax request
},
afterLoading: function(container) {
//Scripts executed after the ajax request
}
});
```### Checking request with PHP (example)
``` php
function is_ajax_request() {
return isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'BAWXMLHttpRequest';
}
```